Debian Codegraph @

engine/Dockerfile

raw
1 # syntax=docker/dockerfile:1
2
3 ARG GO_VERSION=1.24.9
4 ARG BASE_DEBIAN_DISTRO="bookworm"
5 ARG GOLANG_IMAGE="golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO}"
6 ARG XX_VERSION=1.6.1
7
8 # VPNKIT_VERSION is the version of the vpnkit binary which is used as a fallback
9 # network driver for rootless.
10 ARG VPNKIT_VERSION=0.6.0
11
12 # DOCKERCLI_VERSION is the version of the CLI to install in the dev-container.
13 ARG DOCKERCLI_VERSION=v28.2.2
14 ARG DOCKERCLI_REPOSITORY="https://github.com/docker/cli.git"
15
16 # cli version used for integration-cli tests
17 ARG DOCKERCLI_INTEGRATION_REPOSITORY="https://github.com/docker/cli.git"
18 ARG DOCKERCLI_INTEGRATION_VERSION=v18.06.3-ce
19
20 # BUILDX_VERSION is the version of buildx to install in the dev container.
21 ARG BUILDX_VERSION=0.24.0
22
23 # COMPOSE_VERSION is the version of compose to install in the dev container.
24 ARG COMPOSE_VERSION=v2.36.2
25
26 ARG SYSTEMD="false"
27 ARG FIREWALLD="false"
28 ARG DOCKER_STATIC=1
29
30 # REGISTRY_VERSION specifies the version of the registry to download from
31 # https://hub.docker.com/r/distribution/distribution. This version of
32 # the registry is used to test schema 2 manifests. Generally, the version
33 # specified here should match a current release.
34 ARG REGISTRY_VERSION=3.0.0
35
36 # delve is currently only supported on linux/amd64 and linux/arm64;
37 # https://github.com/go-delve/delve/blob/v1.24.1/pkg/proc/native/support_sentinel.go#L1
38 # https://github.com/go-delve/delve/blob/v1.24.1/pkg/proc/native/support_sentinel_linux.go#L1
39 #
40 # ppc64le support was added in v1.21.1, but is still experimental, and requires
41 # the "-tags exp.linuxppc64le" build-tag to be set:
42 # https://github.com/go-delve/delve/commit/71f12207175a1cc09668f856340d8a543c87dcca
43 ARG DELVE_SUPPORTED=${TARGETPLATFORM#linux/amd64} DELVE_SUPPORTED=${DELVE_SUPPORTED#linux/arm64} DELVE_SUPPORTED=${DELVE_SUPPORTED#linux/ppc64le}
44 ARG DELVE_SUPPORTED=${DELVE_SUPPORTED:+"unsupported"}
45 ARG DELVE_SUPPORTED=${DELVE_SUPPORTED:-"supported"}
46
47 # cross compilation helper
48 FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
49
50 # dummy stage to make sure the image is built for deps that don't support some
51 # architectures
52 FROM --platform=$BUILDPLATFORM busybox AS build-dummy
53 RUN mkdir -p /build
54 FROM scratch AS binary-dummy
55 COPY --from=build-dummy /build /build
56
57 # base
58 FROM --platform=$BUILDPLATFORM ${GOLANG_IMAGE} AS base
59 COPY --from=xx / /
60 # Disable collecting local telemetry, as collected by Go and Delve;
61 #
62 # - https://github.com/go-delve/delve/blob/v1.24.1/CHANGELOG.md#1231-2024-09-23
63 # - https://go.dev/doc/telemetry#background
64 RUN go telemetry off && [ "$(go telemetry)" = "off" ] || { echo "Failed to disable Go telemetry"; exit 1; }
65 RUN echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
66 RUN apt-get update && apt-get install --no-install-recommends -y file
67 ENV GO111MODULE=off
68 ENV GOTOOLCHAIN=local
69
70 FROM base AS criu
71 ADD --chmod=0644 https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11/Release.key /etc/apt/trusted.gpg.d/criu.gpg.asc
72 RUN --mount=type=cache,sharing=locked,id=moby-criu-aptlib,target=/var/lib/apt \
73 --mount=type=cache,sharing=locked,id=moby-criu-aptcache,target=/var/cache/apt \
74 echo 'deb https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_12/ /' > /etc/apt/sources.list.d/criu.list \
75 && apt-get update \
76 && apt-get install -y --no-install-recommends criu \
77 && install -D /usr/sbin/criu /build/criu \
78 && /build/criu --version
79
80 # registry
81 FROM distribution/distribution:$REGISTRY_VERSION AS registry
82 RUN mkdir /build && mv /bin/registry /build/registry
83
84 # go-swagger
85 FROM base AS swagger-src
86 WORKDIR /usr/src/swagger
87 # Currently uses a fork from https://github.com/kolyshkin/go-swagger/tree/golang-1.13-fix
88 # TODO: move to under moby/ or fix upstream go-swagger to work for us.
89 RUN git init . && git remote add origin "https://github.com/kolyshkin/go-swagger.git"
90 # GO_SWAGGER_COMMIT specifies the version of the go-swagger binary to build and
91 # install. Go-swagger is used in CI for validating swagger.yaml in hack/validate/swagger-gen
92 ARG GO_SWAGGER_COMMIT=c56166c036004ba7a3a321e5951ba472b9ae298c
93 RUN git fetch -q --depth 1 origin "${GO_SWAGGER_COMMIT}" && git checkout -q FETCH_HEAD
94
95 FROM base AS swagger
96 WORKDIR /go/src/github.com/go-swagger/go-swagger
97 ARG TARGETPLATFORM
98 RUN --mount=from=swagger-src,src=/usr/src/swagger,rw \
99 --mount=type=cache,target=/root/.cache/go-build,id=swagger-build-$TARGETPLATFORM \
100 --mount=type=cache,target=/go/pkg/mod \
101 --mount=type=tmpfs,target=/go/src/ <<EOT
102 set -e
103 xx-go build -o /build/swagger ./cmd/swagger
104 xx-verify /build/swagger
105 EOT
106
107 # frozen-images
108 # See also frozenImages in "testutil/environment/protect.go" (which needs to
109 # be updated when adding images to this list)
110 FROM debian:${BASE_DEBIAN_DISTRO} AS frozen-images
111 RUN --mount=type=cache,sharing=locked,id=moby-frozen-images-aptlib,target=/var/lib/apt \
112 --mount=type=cache,sharing=locked,id=moby-frozen-images-aptcache,target=/var/cache/apt \
113 apt-get update && apt-get install -y --no-install-recommends \
114 ca-certificates \
115 curl \
116 jq
117 # Get useful and necessary Hub images so we can "docker load" locally instead of pulling
118 COPY contrib/download-frozen-image-v2.sh /
119 ARG TARGETARCH
120 ARG TARGETVARIANT
121 RUN /download-frozen-image-v2.sh /build \
122 busybox:latest@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209 \
123 busybox:glibc@sha256:1f81263701cddf6402afe9f33fca0266d9fff379e59b1748f33d3072da71ee85 \
124 debian:bookworm-slim@sha256:2bc5c236e9b262645a323e9088dfa3bb1ecb16cc75811daf40a23a824d665be9 \
125 hello-world:latest@sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9 \
126 arm32v7/hello-world:latest@sha256:50b8560ad574c779908da71f7ce370c0a2471c098d44d1c8f6b513c5a55eeeb1 \
127 hello-world:amd64@sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042 \
128 hello-world:arm64@sha256:963612c5503f3f1674f315c67089dee577d8cc6afc18565e0b4183ae355fb343
129
130 # delve
131 FROM base AS delve-src
132 WORKDIR /usr/src/delve
133 RUN git init . && git remote add origin "https://github.com/go-delve/delve.git"
134 # DELVE_VERSION specifies the version of the Delve debugger binary
135 # from the https://github.com/go-delve/delve repository.
136 # It can be used to run Docker with a possibility of
137 # attaching debugger to it.
138 ARG DELVE_VERSION=v1.24.1
139 RUN git fetch -q --depth 1 origin "${DELVE_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
140
141 FROM base AS delve-supported
142 WORKDIR /usr/src/delve
143 ARG TARGETPLATFORM
144 RUN --mount=from=delve-src,src=/usr/src/delve,rw \
145 --mount=type=cache,target=/root/.cache/go-build,id=delve-build-$TARGETPLATFORM \
146 --mount=type=cache,target=/go/pkg/mod <<EOT
147 set -e
148 GO111MODULE=on xx-go build -o /build/dlv ./cmd/dlv
149 xx-verify /build/dlv
150 EOT
151
152 FROM binary-dummy AS delve-unsupported
153 FROM delve-${DELVE_SUPPORTED} AS delve
154
155 FROM base AS gowinres
156 # GOWINRES_VERSION defines go-winres tool version
157 ARG GOWINRES_VERSION=v0.3.1
158 RUN --mount=type=cache,target=/root/.cache/go-build \
159 --mount=type=cache,target=/go/pkg/mod \
160 GOBIN=/build/ GO111MODULE=on go install "github.com/tc-hib/go-winres@${GOWINRES_VERSION}" \
161 && /build/go-winres --help
162
163 # containerd
164 FROM base AS containerd-src
165 WORKDIR /usr/src/containerd
166 RUN git init . && git remote add origin "https://github.com/containerd/containerd.git"
167 # CONTAINERD_VERSION is used to build containerd binaries, and used for the
168 # integration tests. The distributed docker .deb and .rpm packages depend on a
169 # separate (containerd.io) package, which may be a different version as is
170 # specified here. The containerd golang package is also pinned in vendor.mod.
171 # When updating the binary version you may also need to update the vendor
172 # version to pick up bug fixes or new APIs, however, usually the Go packages
173 # are built from a commit from the master branch.
174 ARG CONTAINERD_VERSION=v1.7.28
175 RUN git fetch -q --depth 1 origin "${CONTAINERD_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
176
177 FROM base AS containerd-build
178 WORKDIR /go/src/github.com/containerd/containerd
179 ARG TARGETPLATFORM
180 RUN --mount=type=cache,sharing=locked,id=moby-containerd-aptlib,target=/var/lib/apt \
181 --mount=type=cache,sharing=locked,id=moby-containerd-aptcache,target=/var/cache/apt \
182 apt-get update && xx-apt-get install -y --no-install-recommends \
183 gcc \
184 pkg-config
185 ARG DOCKER_STATIC
186 RUN --mount=from=containerd-src,src=/usr/src/containerd,rw \
187 --mount=type=cache,target=/root/.cache/go-build,id=containerd-build-$TARGETPLATFORM <<EOT
188 set -e
189 export CC=$(xx-info)-gcc
190 export CGO_ENABLED=$([ "$DOCKER_STATIC" = "1" ] && echo "0" || echo "1")
191 xx-go --wrap
192 make $([ "$DOCKER_STATIC" = "1" ] && echo "STATIC=1") binaries
193 xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/containerd
194 xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/containerd-shim-runc-v2
195 xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/ctr
196 mkdir /build
197 mv bin/containerd bin/containerd-shim-runc-v2 bin/ctr /build
198 EOT
199
200 FROM containerd-build AS containerd-linux
201 FROM binary-dummy AS containerd-windows
202 FROM containerd-${TARGETOS} AS containerd
203
204 FROM base AS golangci_lint
205 ARG GOLANGCI_LINT_VERSION=v2.1.5
206 RUN --mount=type=cache,target=/root/.cache/go-build \
207 --mount=type=cache,target=/go/pkg/mod \
208 GOBIN=/build/ GO111MODULE=on go install "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}" \
209 && /build/golangci-lint --version
210
211 FROM base AS gotestsum
212 # GOTESTSUM_VERSION is the version of gotest.tools/gotestsum to install.
213 ARG GOTESTSUM_VERSION=v1.12.3
214 RUN --mount=type=cache,target=/root/.cache/go-build \
215 --mount=type=cache,target=/go/pkg/mod \
216 GOBIN=/build/ GO111MODULE=on go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" \
217 && /build/gotestsum --version
218
219 FROM base AS shfmt
220 ARG SHFMT_VERSION=v3.8.0
221 RUN --mount=type=cache,target=/root/.cache/go-build \
222 --mount=type=cache,target=/go/pkg/mod \
223 GOBIN=/build/ GO111MODULE=on go install "mvdan.cc/sh/v3/cmd/shfmt@${SHFMT_VERSION}" \
224 && /build/shfmt --version
225
226 FROM base AS gopls
227 RUN --mount=type=cache,target=/root/.cache/go-build \
228 --mount=type=cache,target=/go/pkg/mod \
229 GOBIN=/build/ GO111MODULE=on go install "golang.org/x/tools/gopls@latest" \
230 && /build/gopls version
231
232 FROM base AS dockercli
233 WORKDIR /go/src/github.com/docker/cli
234 ARG DOCKERCLI_REPOSITORY
235 ARG DOCKERCLI_VERSION
236 ARG TARGETPLATFORM
237 RUN --mount=source=hack/dockerfile/cli.sh,target=/download-or-build-cli.sh \
238 --mount=type=cache,id=dockercli-git-$TARGETPLATFORM,sharing=locked,target=./.git \
239 --mount=type=cache,target=/root/.cache/go-build,id=dockercli-build-$TARGETPLATFORM \
240 rm -f ./.git/*.lock \
241 && /download-or-build-cli.sh ${DOCKERCLI_VERSION} ${DOCKERCLI_REPOSITORY} /build \
242 && /build/docker --version \
243 && /build/docker completion bash >/completion.bash
244
245 FROM base AS dockercli-integration
246 WORKDIR /go/src/github.com/docker/cli
247 ARG DOCKERCLI_INTEGRATION_REPOSITORY
248 ARG DOCKERCLI_INTEGRATION_VERSION
249 ARG TARGETPLATFORM
250 RUN --mount=source=hack/dockerfile/cli.sh,target=/download-or-build-cli.sh \
251 --mount=type=cache,id=dockercli-git-$TARGETPLATFORM,sharing=locked,target=./.git \
252 --mount=type=cache,target=/root/.cache/go-build,id=dockercli-build-$TARGETPLATFORM \
253 rm -f ./.git/*.lock \
254 && /download-or-build-cli.sh ${DOCKERCLI_INTEGRATION_VERSION} ${DOCKERCLI_INTEGRATION_REPOSITORY} /build \
255 && /build/docker --version
256
257 # runc
258 FROM base AS runc-src
259 WORKDIR /usr/src/runc
260 RUN git init . && git remote add origin "https://github.com/opencontainers/runc.git"
261 # RUNC_VERSION should match the version that is used by the containerd version
262 # that is used. If you need to update runc, open a pull request in the containerd
263 # project first, and update both after that is merged.
264 ARG RUNC_VERSION=v1.3.3
265 RUN git fetch -q --depth 1 origin "${RUNC_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
266
267 FROM base AS runc-build
268 WORKDIR /go/src/github.com/opencontainers/runc
269 ARG TARGETPLATFORM
270 RUN --mount=type=cache,sharing=locked,id=moby-runc-aptlib,target=/var/lib/apt \
271 --mount=type=cache,sharing=locked,id=moby-runc-aptcache,target=/var/cache/apt \
272 apt-get update && xx-apt-get install -y --no-install-recommends \
273 gcc \
274 libc6-dev \
275 libseccomp-dev \
276 pkg-config
277 ARG DOCKER_STATIC
278 RUN --mount=from=runc-src,src=/usr/src/runc,rw \
279 --mount=type=cache,target=/root/.cache/go-build,id=runc-build-$TARGETPLATFORM <<EOT
280 set -e
281 xx-go --wrap
282 CGO_ENABLED=1 make "$([ "$DOCKER_STATIC" = "1" ] && echo "static" || echo "runc")"
283 xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") runc
284 mkdir /build
285 mv runc /build/
286 EOT
287
288 FROM runc-build AS runc-linux
289 FROM binary-dummy AS runc-windows
290 FROM runc-${TARGETOS} AS runc
291
292 # tini
293 FROM base AS tini-src
294 WORKDIR /usr/src/tini
295 RUN git init . && git remote add origin "https://github.com/krallin/tini.git"
296 # TINI_VERSION specifies the version of tini (docker-init) to build. This
297 # binary is used when starting containers with the `--init` option.
298 ARG TINI_VERSION=v0.19.0
299 RUN git fetch -q --depth 1 origin "${TINI_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
300
301 FROM base AS tini-build
302 WORKDIR /go/src/github.com/krallin/tini
303 RUN --mount=type=cache,sharing=locked,id=moby-tini-aptlib,target=/var/lib/apt \
304 --mount=type=cache,sharing=locked,id=moby-tini-aptcache,target=/var/cache/apt \
305 apt-get update && apt-get install -y --no-install-recommends cmake
306 ARG TARGETPLATFORM
307 RUN --mount=type=cache,sharing=locked,id=moby-tini-aptlib,target=/var/lib/apt \
308 --mount=type=cache,sharing=locked,id=moby-tini-aptcache,target=/var/cache/apt \
309 xx-apt-get install -y --no-install-recommends \
310 gcc \
311 libc6-dev \
312 pkg-config
313 RUN --mount=from=tini-src,src=/usr/src/tini,rw \
314 --mount=type=cache,target=/root/.cache/go-build,id=tini-build-$TARGETPLATFORM <<EOT
315 set -e
316 CC=$(xx-info)-gcc cmake .
317 make tini-static
318 xx-verify --static tini-static
319 mkdir /build
320 mv tini-static /build/docker-init
321 EOT
322
323 FROM tini-build AS tini-linux
324 FROM binary-dummy AS tini-windows
325 FROM tini-${TARGETOS} AS tini
326
327 # rootlesskit
328 FROM base AS rootlesskit-src
329 WORKDIR /usr/src/rootlesskit
330 RUN git init . && git remote add origin "https://github.com/rootless-containers/rootlesskit.git"
331 # When updating, also update vendor.mod and hack/dockerfile/install/rootlesskit.installer accordingly.
332 ARG ROOTLESSKIT_VERSION=v2.3.4
333 RUN git fetch -q --depth 1 origin "${ROOTLESSKIT_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
334
335 FROM base AS rootlesskit-build
336 WORKDIR /go/src/github.com/rootless-containers/rootlesskit
337 ARG TARGETPLATFORM
338 RUN --mount=type=cache,sharing=locked,id=moby-rootlesskit-aptlib,target=/var/lib/apt \
339 --mount=type=cache,sharing=locked,id=moby-rootlesskit-aptcache,target=/var/cache/apt \
340 apt-get update && xx-apt-get install -y --no-install-recommends \
341 gcc \
342 libc6-dev \
343 pkg-config
344 ENV GO111MODULE=on
345 ARG DOCKER_STATIC
346 RUN --mount=from=rootlesskit-src,src=/usr/src/rootlesskit,rw \
347 --mount=type=cache,target=/go/pkg/mod \
348 --mount=type=cache,target=/root/.cache/go-build,id=rootlesskit-build-$TARGETPLATFORM <<EOT
349 set -e
350 export CGO_ENABLED=$([ "$DOCKER_STATIC" = "1" ] && echo "0" || echo "1")
351 xx-go build -o /build/rootlesskit -ldflags="$([ "$DOCKER_STATIC" != "1" ] && echo "-linkmode=external")" ./cmd/rootlesskit
352 xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") /build/rootlesskit
353 EOT
354 COPY --link ./contrib/dockerd-rootless.sh /build/
355 COPY --link ./contrib/dockerd-rootless-setuptool.sh /build/
356
357 FROM rootlesskit-build AS rootlesskit-linux
358 FROM binary-dummy AS rootlesskit-windows
359 FROM rootlesskit-${TARGETOS} AS rootlesskit
360
361 FROM base AS crun
362 # CRUN_VERSION is the version of crun to install in the dev-container.
363 ARG CRUN_VERSION=1.21
364 RUN --mount=type=cache,sharing=locked,id=moby-crun-aptlib,target=/var/lib/apt \
365 --mount=type=cache,sharing=locked,id=moby-crun-aptcache,target=/var/cache/apt \
366 apt-get update && apt-get install -y --no-install-recommends \
367 autoconf \
368 automake \
369 build-essential \
370 libcap-dev \
371 libprotobuf-c-dev \
372 libseccomp-dev \
373 libsystemd-dev \
374 libtool \
375 libyajl-dev \
376 python3 \
377 ;
378 RUN --mount=type=tmpfs,target=/tmp/crun-build \
379 git clone https://github.com/containers/crun.git /tmp/crun-build && \
380 cd /tmp/crun-build && \
381 git checkout -q "${CRUN_VERSION}" && \
382 ./autogen.sh && \
383 ./configure --bindir=/build && \
384 make -j install
385
386 # vpnkit
387 # use dummy scratch stage to avoid build to fail for unsupported platforms
388 FROM scratch AS vpnkit-windows
389 FROM scratch AS vpnkit-linux-386
390 FROM scratch AS vpnkit-linux-arm
391 FROM scratch AS vpnkit-linux-ppc64le
392 FROM scratch AS vpnkit-linux-riscv64
393 FROM scratch AS vpnkit-linux-s390x
394 FROM moby/vpnkit-bin:${VPNKIT_VERSION} AS vpnkit-linux-amd64
395 FROM moby/vpnkit-bin:${VPNKIT_VERSION} AS vpnkit-linux-arm64
396 FROM vpnkit-linux-${TARGETARCH} AS vpnkit-linux
397 FROM vpnkit-${TARGETOS} AS vpnkit
398
399 # containerutility
400 FROM base AS containerutil-src
401 WORKDIR /usr/src/containerutil
402 RUN git init . && git remote add origin "https://github.com/docker-archive/windows-container-utility.git"
403 ARG CONTAINERUTILITY_VERSION=aa1ba87e99b68e0113bd27ec26c60b88f9d4ccd9
404 RUN git fetch -q --depth 1 origin "${CONTAINERUTILITY_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
405
406 FROM base AS containerutil-build
407 WORKDIR /usr/src/containerutil
408 ARG TARGETPLATFORM
409 RUN xx-apt-get install -y --no-install-recommends \
410 gcc \
411 g++ \
412 libc6-dev \
413 pkg-config
414 RUN --mount=from=containerutil-src,src=/usr/src/containerutil,rw \
415 --mount=type=cache,target=/root/.cache/go-build,id=containerutil-build-$TARGETPLATFORM <<EOT
416 set -e
417 CC="$(xx-info)-gcc" CXX="$(xx-info)-g++" make
418 xx-verify --static containerutility.exe
419 mkdir /build
420 mv containerutility.exe /build/
421 EOT
422
423 FROM binary-dummy AS containerutil-linux
424 FROM containerutil-build AS containerutil-windows-amd64
425 FROM containerutil-windows-${TARGETARCH} AS containerutil-windows
426 FROM containerutil-${TARGETOS} AS containerutil
427 FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx
428 FROM docker/compose-bin:${COMPOSE_VERSION} AS compose
429
430 FROM base AS dev-systemd-false
431 COPY --link --from=frozen-images /build/ /docker-frozen-images
432 COPY --link --from=swagger /build/ /usr/local/bin/
433 COPY --link --from=delve /build/ /usr/local/bin/
434 COPY --link --from=gowinres /build/ /usr/local/bin/
435 COPY --link --from=tini /build/ /usr/local/bin/
436 COPY --link --from=registry /build/ /usr/local/bin/
437
438 # Skip the CRIU stage for now, as the opensuse package repository is sometimes
439 # unstable, and we're currently not using it in CI.
440 #
441 # FIXME(thaJeztah): re-enable this stage when https://github.com/moby/moby/issues/38963 is resolved (see https://github.com/moby/moby/pull/38984)
442 # COPY --link --from=criu /build/ /usr/local/bin/
443 COPY --link --from=gotestsum /build/ /usr/local/bin/
444 COPY --link --from=golangci_lint /build/ /usr/local/bin/
445 COPY --link --from=shfmt /build/ /usr/local/bin/
446 COPY --link --from=runc /build/ /usr/local/bin/
447 COPY --link --from=containerd /build/ /usr/local/bin/
448 COPY --link --from=rootlesskit /build/ /usr/local/bin/
449 COPY --link --from=vpnkit / /usr/local/bin/
450 COPY --link --from=containerutil /build/ /usr/local/bin/
451 COPY --link --from=crun /build/ /usr/local/bin/
452 COPY --link hack/dockerfile/etc/docker/ /etc/docker/
453 COPY --link --from=buildx /buildx /usr/local/libexec/docker/cli-plugins/docker-buildx
454 COPY --link --from=compose /docker-compose /usr/libexec/docker/cli-plugins/docker-compose
455
456 ENV PATH=/usr/local/cli:$PATH
457 ENV TEST_CLIENT_BINARY=/usr/local/cli-integration/docker
458 ENV CONTAINERD_ADDRESS=/run/docker/containerd/containerd.sock
459 ENV CONTAINERD_NAMESPACE=moby
460 WORKDIR /go/src/github.com/docker/docker
461 VOLUME /var/lib/docker
462 VOLUME /home/unprivilegeduser/.local/share/docker
463 # Wrap all commands in the "docker-in-docker" script to allow nested containers
464 ENTRYPOINT ["hack/dind"]
465
466 FROM dev-systemd-false AS dev-systemd-true
467 RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
468 --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \
469 apt-get update && apt-get install -y --no-install-recommends \
470 dbus \
471 dbus-user-session \
472 systemd \
473 systemd-sysv
474 ENTRYPOINT ["hack/dind-systemd"]
475
476 FROM dev-systemd-${SYSTEMD} AS dev-firewalld-false
477
478 FROM dev-systemd-true AS dev-firewalld-true
479 RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
480 --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \
481 apt-get update && apt-get install -y --no-install-recommends \
482 firewalld
483
484 FROM dev-firewalld-${FIREWALLD} AS dev-base
485 RUN groupadd -r docker
486 RUN useradd --create-home --gid docker unprivilegeduser \
487 && mkdir -p /home/unprivilegeduser/.local/share/docker \
488 && chown -R unprivilegeduser /home/unprivilegeduser
489 # Let us use a .bashrc file
490 RUN ln -sfv /go/src/github.com/docker/docker/.bashrc ~/.bashrc
491 # Activate bash completion
492 RUN echo "source /usr/share/bash-completion/bash_completion" >> /etc/bash.bashrc
493 RUN ldconfig
494 # Set dev environment as safe git directory to prevent "dubious ownership" errors
495 # when bind-mounting the source into the dev-container. See https://github.com/moby/moby/pull/44930
496 RUN git config --global --add safe.directory $GOPATH/src/github.com/docker/docker
497 # This should only install packages that are specifically needed for the dev environment and nothing else
498 # Do you really need to add another package here? Can it be done in a different build stage?
499 RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
500 --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \
501 apt-get update && apt-get install -y --no-install-recommends \
502 apparmor \
503 bash-completion \
504 bzip2 \
505 inetutils-ping \
506 iproute2 \
507 iptables \
508 nftables \
509 jq \
510 libcap2-bin \
511 libnet1 \
512 libnl-3-200 \
513 libprotobuf-c1 \
514 libyajl2 \
515 nano \
516 net-tools \
517 netcat-openbsd \
518 patch \
519 pigz \
520 sudo \
521 systemd-journal-remote \
522 thin-provisioning-tools \
523 uidmap \
524 vim \
525 vim-common \
526 xfsprogs \
527 xz-utils \
528 zip \
529 zstd
530 RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
531 --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \
532 apt-get update && apt-get install --no-install-recommends -y \
533 gcc \
534 pkg-config \
535 libseccomp-dev \
536 libsystemd-dev \
537 yamllint
538 COPY --link --from=dockercli /build/ /usr/local/cli
539 COPY --link --from=dockercli /completion.bash /etc/bash_completion.d/docker
540 COPY --link --from=dockercli-integration /build/ /usr/local/cli-integration
541
542 FROM base AS build
543 COPY --from=gowinres /build/ /usr/local/bin/
544 WORKDIR /go/src/github.com/docker/docker
545 ENV GO111MODULE=off
546 ENV CGO_ENABLED=1
547 RUN --mount=type=cache,sharing=locked,id=moby-build-aptlib,target=/var/lib/apt \
548 --mount=type=cache,sharing=locked,id=moby-build-aptcache,target=/var/cache/apt \
549 apt-get update && apt-get install --no-install-recommends -y \
550 clang \
551 lld \
552 llvm
553 ARG TARGETPLATFORM
554 RUN --mount=type=cache,sharing=locked,id=moby-build-aptlib,target=/var/lib/apt \
555 --mount=type=cache,sharing=locked,id=moby-build-aptcache,target=/var/cache/apt \
556 xx-apt-get install --no-install-recommends -y \
557 gcc \
558 libc6-dev \
559 libseccomp-dev \
560 libsystemd-dev \
561 pkg-config
562 ARG DOCKER_BUILDTAGS
563 ARG DOCKER_DEBUG
564 ARG DOCKER_GITCOMMIT=HEAD
565 ARG DOCKER_LDFLAGS
566 ARG DOCKER_STATIC
567 ARG VERSION
568 ARG PLATFORM
569 ARG PRODUCT
570 ARG DEFAULT_PRODUCT_LICENSE
571 ARG PACKAGER_NAME
572 # PREFIX overrides DEST dir in make.sh script otherwise it fails because of
573 # read only mount in current work dir
574 ENV PREFIX=/tmp
575 RUN <<EOT
576 # in bullseye arm64 target does not link with lld so configure it to use ld instead
577 if [ "$(xx-info arch)" = "arm64" ]; then
578 XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple
579 fi
580 EOT
581 RUN --mount=type=bind,target=.,rw \
582 --mount=type=tmpfs,target=cli/winresources/dockerd \
583 --mount=type=cache,target=/root/.cache/go-build,id=moby-build-$TARGETPLATFORM <<EOT
584 set -e
585 target=$([ "$DOCKER_STATIC" = "1" ] && echo "binary" || echo "dynbinary")
586 xx-go --wrap
587 PKG_CONFIG=$(xx-go env PKG_CONFIG) ./hack/make.sh $target
588 xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") /tmp/bundles/${target}-daemon/dockerd$([ "$(xx-info os)" = "windows" ] && echo ".exe")
589 [ "$(xx-info os)" != "linux" ] || xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") /tmp/bundles/${target}-daemon/docker-proxy
590 mkdir /build
591 mv /tmp/bundles/${target}-daemon/* /build/
592 EOT
593
594 # usage:
595 # > docker buildx bake binary
596 # > DOCKER_STATIC=0 docker buildx bake binary
597 # or
598 # > make binary
599 # > make dynbinary
600 FROM scratch AS binary
601 COPY --from=build /build/ /
602
603 # usage:
604 # > docker buildx bake all
605 FROM scratch AS all
606 COPY --link --from=tini /build/ /
607 COPY --link --from=runc /build/ /
608 COPY --link --from=containerd /build/ /
609 COPY --link --from=rootlesskit /build/ /
610 COPY --link --from=containerutil /build/ /
611 COPY --link --from=vpnkit / /
612 COPY --link --from=build /build /
613
614 # smoke tests
615 # usage:
616 # > docker buildx bake binary-smoketest
617 FROM base AS smoketest
618 WORKDIR /usr/local/bin
619 COPY --from=build /build .
620 RUN <<EOT
621 set -ex
622 file dockerd
623 dockerd --version
624 file docker-proxy
625 docker-proxy --version
626 EOT
627
628 # devcontainer is a stage used by .devcontainer/devcontainer.json
629 FROM dev-base AS devcontainer
630 COPY --link . .
631 COPY --link --from=gopls /build/ /usr/local/bin/
632
633 # usage:
634 # > docker buildx bake dind
635 # > docker run -d --restart always --privileged --name devdind -p 12375:2375 docker-dind --debug --host=tcp://0.0.0.0:2375 --tlsverify=false
636 FROM docker:dind AS dind
637 COPY --link --from=dockercli /build/docker /usr/local/bin/
638 COPY --link --from=buildx /buildx /usr/local/libexec/docker/cli-plugins/docker-buildx
639 COPY --link --from=compose /docker-compose /usr/local/libexec/docker/cli-plugins/docker-compose
640 COPY --link --from=all / /usr/local/bin/
641
642 # usage:
643 # > make shell
644 # > SYSTEMD=true make shell
645 FROM dev-base AS dev
646 COPY --link . .