Quellcode durchsuchen

Merge pull request #40493 from AkihiroSuda/dockerfile-systemd

integration: use systemd when $DOCKER_SYSTEMD is set
Sebastiaan van Stijn vor 5 Jahren
Ursprung
Commit
e2b7793a1b
3 geänderte Dateien mit 21 neuen und 3 gelöschten Zeilen
  1. 16 2
      Dockerfile
  2. 4 0
      Makefile
  3. 1 1
      integration/system/cgroupdriver_systemd_test.go

+ 16 - 2
Dockerfile

@@ -1,6 +1,7 @@
 # syntax=docker/dockerfile:1.1.3-experimental
 
 ARG CROSS="false"
+ARG SYSTEMD="false"
 ARG GO_VERSION=1.13.8
 ARG DEBIAN_FRONTEND=noninteractive
 ARG VPNKIT_DIGEST=e508a17cfacc8fd39261d5b4e397df2b953690da577e2c987a47630cd0c42f8e
@@ -248,7 +249,7 @@ COPY ./contrib/dockerd-rootless.sh /build
 FROM djs55/vpnkit@sha256:${VPNKIT_DIGEST} AS vpnkit
 
 # TODO: Some of this is only really needed for testing, it would be nice to split this up
-FROM runtime-dev AS dev
+FROM runtime-dev AS dev-systemd-false
 ARG DEBIAN_FRONTEND
 RUN groupadd -r docker
 RUN useradd --create-home --gid docker unprivilegeduser
@@ -317,6 +318,19 @@ VOLUME /var/lib/docker
 # Wrap all commands in the "docker-in-docker" script to allow nested containers
 ENTRYPOINT ["hack/dind"]
 
+FROM dev-systemd-false AS dev-systemd-true
+RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
+    --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \
+        apt-get update && apt-get install -y --no-install-recommends \
+            dbus \
+            dbus-user-session \
+            systemd \
+            systemd-sysv
+RUN mkdir -p hack \
+  && curl -o hack/dind-systemd https://raw.githubusercontent.com/AkihiroSuda/containerized-systemd/b70bac0daeea120456764248164c21684ade7d0d/docker-entrypoint.sh \
+  && chmod +x hack/dind-systemd
+ENTRYPOINT ["hack/dind-systemd"]
+
 FROM runtime-dev AS binary-base
 ARG DOCKER_GITCOMMIT=HEAD
 ENV DOCKER_GITCOMMIT=${DOCKER_GITCOMMIT}
@@ -368,5 +382,5 @@ COPY --from=build-dynbinary /build/bundles/ /
 FROM scratch AS cross
 COPY --from=build-cross /build/bundles/ /
 
-FROM dev AS final
+FROM dev-systemd-${SYSTEMD} AS final
 COPY . /go/src/github.com/docker/docker

+ 4 - 0
Makefile

@@ -142,6 +142,10 @@ endif
 DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)"
 
 DOCKER_BUILD_ARGS += --build-arg=GO_VERSION
+ifdef DOCKER_SYSTEMD
+DOCKER_BUILD_ARGS += --build-arg=SYSTEMD=true
+endif
+
 BUILD_OPTS := ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -f "$(DOCKERFILE)"
 ifdef USE_BUILDX
 BUILD_OPTS += $(BUILDX_BUILD_EXTRA_OPTS)

+ 1 - 1
integration/system/cgroupdriver_systemd_test.go

@@ -38,7 +38,7 @@ func TestCgroupDriverSystemdMemoryLimit(t *testing.T) {
 	d.StartWithBusybox(t, "--exec-opt", "native.cgroupdriver=systemd", "--iptables=false")
 	defer d.Stop(t)
 
-	const mem = 64 * 1024 * 1024 // 64 MB
+	const mem = int64(64 * 1024 * 1024) // 64 MB
 
 	ctx := context.Background()
 	ctrID := container.Create(ctx, t, c, func(ctr *container.TestContainerConfig) {