Dockerfile 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. # syntax=docker/dockerfile:1.3
  2. ARG CROSS="false"
  3. ARG SYSTEMD="false"
  4. # IMPORTANT: When updating this please note that stdlib archive/tar pkg is vendored
  5. ARG GO_VERSION=1.17.5
  6. ARG DEBIAN_FRONTEND=noninteractive
  7. ARG VPNKIT_VERSION=0.5.0
  8. ARG DOCKER_BUILDTAGS="apparmor seccomp"
  9. ARG BASE_DEBIAN_DISTRO="bullseye"
  10. ARG GOLANG_IMAGE="golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO}"
  11. FROM ${GOLANG_IMAGE} AS base
  12. RUN echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
  13. ARG APT_MIRROR
  14. RUN sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" /etc/apt/sources.list \
  15. && sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" /etc/apt/sources.list
  16. ENV GO111MODULE=off
  17. FROM base AS criu
  18. ARG DEBIAN_FRONTEND
  19. ADD --chmod=0644 https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11/Release.key /etc/apt/trusted.gpg.d/criu.gpg.asc
  20. RUN --mount=type=cache,sharing=locked,id=moby-criu-aptlib,target=/var/lib/apt \
  21. --mount=type=cache,sharing=locked,id=moby-criu-aptcache,target=/var/cache/apt \
  22. echo 'deb https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11/ /' > /etc/apt/sources.list.d/criu.list \
  23. && apt-get update \
  24. && apt-get install -y --no-install-recommends criu \
  25. && install -D /usr/sbin/criu /build/criu
  26. FROM base AS registry
  27. WORKDIR /go/src/github.com/docker/distribution
  28. # REGISTRY_VERSION specifies the version of the registry to build and install
  29. # from the https://github.com/docker/distribution repository. This version of
  30. # the registry is used to test both schema 1 and schema 2 manifests. Generally,
  31. # the version specified here should match a current release.
  32. ARG REGISTRY_VERSION=v2.3.0
  33. # REGISTRY_VERSION_SCHEMA1 specifies the version of the regsitry to build and
  34. # install from the https://github.com/docker/distribution repository. This is
  35. # an older (pre v2.3.0) version of the registry that only supports schema1
  36. # manifests. This version of the registry is not working on arm64, so installation
  37. # is skipped on that architecture.
  38. ARG REGISTRY_VERSION_SCHEMA1=v2.1.0
  39. RUN --mount=type=cache,target=/root/.cache/go-build \
  40. --mount=type=cache,target=/go/pkg/mod \
  41. --mount=type=tmpfs,target=/go/src/ \
  42. set -x \
  43. && git clone https://github.com/docker/distribution.git . \
  44. && git checkout -q "$REGISTRY_VERSION" \
  45. && GOPATH="/go/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
  46. go build -buildmode=pie -o /build/registry-v2 github.com/docker/distribution/cmd/registry \
  47. && case $(dpkg --print-architecture) in \
  48. amd64|armhf|ppc64*|s390x) \
  49. git checkout -q "$REGISTRY_VERSION_SCHEMA1"; \
  50. GOPATH="/go/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH"; \
  51. go build -buildmode=pie -o /build/registry-v2-schema1 github.com/docker/distribution/cmd/registry; \
  52. ;; \
  53. esac
  54. FROM base AS swagger
  55. WORKDIR $GOPATH/src/github.com/go-swagger/go-swagger
  56. # GO_SWAGGER_COMMIT specifies the version of the go-swagger binary to build and
  57. # install. Go-swagger is used in CI for validating swagger.yaml in hack/validate/swagger-gen
  58. #
  59. # Currently uses a fork from https://github.com/kolyshkin/go-swagger/tree/golang-1.13-fix,
  60. # TODO: move to under moby/ or fix upstream go-swagger to work for us.
  61. ENV GO_SWAGGER_COMMIT c56166c036004ba7a3a321e5951ba472b9ae298c
  62. RUN --mount=type=cache,target=/root/.cache/go-build \
  63. --mount=type=cache,target=/go/pkg/mod \
  64. --mount=type=tmpfs,target=/go/src/ \
  65. set -x \
  66. && git clone https://github.com/kolyshkin/go-swagger.git . \
  67. && git checkout -q "$GO_SWAGGER_COMMIT" \
  68. && go build -o /build/swagger github.com/go-swagger/go-swagger/cmd/swagger
  69. FROM debian:${BASE_DEBIAN_DISTRO} AS frozen-images
  70. ARG DEBIAN_FRONTEND
  71. RUN --mount=type=cache,sharing=locked,id=moby-frozen-images-aptlib,target=/var/lib/apt \
  72. --mount=type=cache,sharing=locked,id=moby-frozen-images-aptcache,target=/var/cache/apt \
  73. apt-get update && apt-get install -y --no-install-recommends \
  74. ca-certificates \
  75. curl \
  76. jq
  77. # Get useful and necessary Hub images so we can "docker load" locally instead of pulling
  78. COPY contrib/download-frozen-image-v2.sh /
  79. ARG TARGETARCH
  80. RUN /download-frozen-image-v2.sh /build \
  81. busybox:latest@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209 \
  82. busybox:glibc@sha256:1f81263701cddf6402afe9f33fca0266d9fff379e59b1748f33d3072da71ee85 \
  83. debian:bullseye-slim@sha256:dacf278785a4daa9de07596ec739dbc07131e189942772210709c5c0777e8437 \
  84. hello-world:latest@sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9 \
  85. arm32v7/hello-world:latest@sha256:50b8560ad574c779908da71f7ce370c0a2471c098d44d1c8f6b513c5a55eeeb1
  86. # See also frozenImages in "testutil/environment/protect.go" (which needs to be updated when adding images to this list)
  87. FROM base AS cross-false
  88. FROM --platform=linux/amd64 base AS cross-true
  89. ARG DEBIAN_FRONTEND
  90. RUN dpkg --add-architecture arm64
  91. RUN dpkg --add-architecture armel
  92. RUN dpkg --add-architecture armhf
  93. RUN dpkg --add-architecture ppc64el
  94. RUN dpkg --add-architecture s390x
  95. RUN --mount=type=cache,sharing=locked,id=moby-cross-true-aptlib,target=/var/lib/apt \
  96. --mount=type=cache,sharing=locked,id=moby-cross-true-aptcache,target=/var/cache/apt \
  97. apt-get update && apt-get install -y --no-install-recommends \
  98. crossbuild-essential-arm64 \
  99. crossbuild-essential-armel \
  100. crossbuild-essential-armhf \
  101. crossbuild-essential-ppc64el \
  102. crossbuild-essential-s390x
  103. FROM cross-${CROSS} AS dev-base
  104. FROM dev-base AS runtime-dev-cross-false
  105. ARG DEBIAN_FRONTEND
  106. RUN --mount=type=cache,sharing=locked,id=moby-cross-false-aptlib,target=/var/lib/apt \
  107. --mount=type=cache,sharing=locked,id=moby-cross-false-aptcache,target=/var/cache/apt \
  108. apt-get update && apt-get install -y --no-install-recommends \
  109. binutils-mingw-w64 \
  110. g++-mingw-w64-x86-64 \
  111. libapparmor-dev \
  112. libbtrfs-dev \
  113. libdevmapper-dev \
  114. libseccomp-dev \
  115. libsystemd-dev \
  116. libudev-dev
  117. FROM --platform=linux/amd64 runtime-dev-cross-false AS runtime-dev-cross-true
  118. ARG DEBIAN_FRONTEND
  119. # These crossbuild packages rely on gcc-<arch>, but this doesn't want to install
  120. # on non-amd64 systems, so other architectures cannnot crossbuild amd64.
  121. RUN --mount=type=cache,sharing=locked,id=moby-cross-true-aptlib,target=/var/lib/apt \
  122. --mount=type=cache,sharing=locked,id=moby-cross-true-aptcache,target=/var/cache/apt \
  123. apt-get update && apt-get install -y --no-install-recommends \
  124. libapparmor-dev:arm64 \
  125. libapparmor-dev:armel \
  126. libapparmor-dev:armhf \
  127. libapparmor-dev:ppc64el \
  128. libapparmor-dev:s390x \
  129. libseccomp-dev:arm64 \
  130. libseccomp-dev:armel \
  131. libseccomp-dev:armhf \
  132. libseccomp-dev:ppc64el \
  133. libseccomp-dev:s390x
  134. FROM runtime-dev-cross-${CROSS} AS runtime-dev
  135. FROM base AS tomll
  136. # GOTOML_VERSION specifies the version of the tomll binary to build and install
  137. # from the https://github.com/pelletier/go-toml repository. This binary is used
  138. # in CI in the hack/validate/toml script.
  139. #
  140. # When updating this version, consider updating the github.com/pelletier/go-toml
  141. # dependency in vendor.conf accordingly.
  142. ARG GOTOML_VERSION=v1.8.1
  143. RUN --mount=type=cache,target=/root/.cache/go-build \
  144. --mount=type=cache,target=/go/pkg/mod \
  145. GOBIN=/build/ GO111MODULE=on go install "github.com/pelletier/go-toml/cmd/tomll@${GOTOML_VERSION}" \
  146. && /build/tomll --help
  147. FROM base AS vndr
  148. # VNDR_VERSION specifies the version of the vndr tool to build and install
  149. # from the https://github.com/LK4D4/vndr repository.
  150. #
  151. # The vndr tool is used to manage vendored go packages in the vendor directory,
  152. # and is pinned to a fixed version because different versions of this tool
  153. # can result in differences in the (go) files that are considered for vendoring.
  154. ARG VNDR_VERSION=v0.1.2
  155. RUN --mount=type=cache,target=/root/.cache/go-build \
  156. --mount=type=cache,target=/go/pkg/mod \
  157. GOBIN=/build/ GO111MODULE=on go install "github.com/LK4D4/vndr@${VNDR_VERSION}" \
  158. && /build/vndr --help
  159. FROM dev-base AS containerd
  160. ARG DEBIAN_FRONTEND
  161. RUN --mount=type=cache,sharing=locked,id=moby-containerd-aptlib,target=/var/lib/apt \
  162. --mount=type=cache,sharing=locked,id=moby-containerd-aptcache,target=/var/cache/apt \
  163. apt-get update && apt-get install -y --no-install-recommends \
  164. libbtrfs-dev
  165. ARG CONTAINERD_VERSION
  166. COPY /hack/dockerfile/install/install.sh /hack/dockerfile/install/containerd.installer /
  167. RUN --mount=type=cache,target=/root/.cache/go-build \
  168. --mount=type=cache,target=/go/pkg/mod \
  169. PREFIX=/build /install.sh containerd
  170. FROM base AS golangci_lint
  171. ARG GOLANGCI_LINT_VERSION=v1.23.8
  172. RUN --mount=type=cache,target=/root/.cache/go-build \
  173. --mount=type=cache,target=/go/pkg/mod \
  174. GOBIN=/build/ GO111MODULE=on go install "github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}" \
  175. && /build/golangci-lint --version
  176. FROM base AS gotestsum
  177. ARG GOTESTSUM_VERSION=v1.7.0
  178. RUN --mount=type=cache,target=/root/.cache/go-build \
  179. --mount=type=cache,target=/go/pkg/mod \
  180. GOBIN=/build/ GO111MODULE=on go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" \
  181. && /build/gotestsum --version
  182. FROM base AS shfmt
  183. ARG SHFMT_VERSION=v3.0.2
  184. RUN --mount=type=cache,target=/root/.cache/go-build \
  185. --mount=type=cache,target=/go/pkg/mod \
  186. GOBIN=/build/ GO111MODULE=on go install "mvdan.cc/sh/v3/cmd/shfmt@${SHFMT_VERSION}" \
  187. && /build/shfmt --version
  188. FROM dev-base AS dockercli
  189. ARG DOCKERCLI_CHANNEL
  190. ARG DOCKERCLI_VERSION
  191. COPY /hack/dockerfile/install/install.sh /hack/dockerfile/install/dockercli.installer /
  192. RUN --mount=type=cache,target=/root/.cache/go-build \
  193. --mount=type=cache,target=/go/pkg/mod \
  194. PREFIX=/build /install.sh dockercli
  195. FROM runtime-dev AS runc
  196. ARG RUNC_VERSION
  197. ARG RUNC_BUILDTAGS
  198. COPY /hack/dockerfile/install/install.sh /hack/dockerfile/install/runc.installer /
  199. RUN --mount=type=cache,target=/root/.cache/go-build \
  200. --mount=type=cache,target=/go/pkg/mod \
  201. PREFIX=/build /install.sh runc
  202. FROM dev-base AS tini
  203. ARG DEBIAN_FRONTEND
  204. ARG TINI_VERSION
  205. RUN --mount=type=cache,sharing=locked,id=moby-tini-aptlib,target=/var/lib/apt \
  206. --mount=type=cache,sharing=locked,id=moby-tini-aptcache,target=/var/cache/apt \
  207. apt-get update && apt-get install -y --no-install-recommends \
  208. cmake \
  209. vim-common
  210. COPY /hack/dockerfile/install/install.sh /hack/dockerfile/install/tini.installer /
  211. RUN --mount=type=cache,target=/root/.cache/go-build \
  212. --mount=type=cache,target=/go/pkg/mod \
  213. PREFIX=/build /install.sh tini
  214. FROM dev-base AS rootlesskit
  215. ARG ROOTLESSKIT_VERSION
  216. ARG PREFIX=/build
  217. COPY /hack/dockerfile/install/install.sh /hack/dockerfile/install/rootlesskit.installer /
  218. RUN --mount=type=cache,target=/root/.cache/go-build \
  219. --mount=type=cache,target=/go/pkg/mod \
  220. /install.sh rootlesskit \
  221. && "${PREFIX}"/rootlesskit --version \
  222. && "${PREFIX}"/rootlesskit-docker-proxy --help
  223. COPY ./contrib/dockerd-rootless.sh /build
  224. COPY ./contrib/dockerd-rootless-setuptool.sh /build
  225. FROM --platform=amd64 djs55/vpnkit:${VPNKIT_VERSION} AS vpnkit-amd64
  226. FROM --platform=arm64 djs55/vpnkit:${VPNKIT_VERSION} AS vpnkit-arm64
  227. FROM scratch AS vpnkit
  228. COPY --from=vpnkit-amd64 /vpnkit /build/vpnkit.x86_64
  229. COPY --from=vpnkit-arm64 /vpnkit /build/vpnkit.aarch64
  230. # TODO: Some of this is only really needed for testing, it would be nice to split this up
  231. FROM runtime-dev AS dev-systemd-false
  232. ARG DEBIAN_FRONTEND
  233. RUN groupadd -r docker
  234. RUN useradd --create-home --gid docker unprivilegeduser \
  235. && mkdir -p /home/unprivilegeduser/.local/share/docker \
  236. && chown -R unprivilegeduser /home/unprivilegeduser
  237. # Let us use a .bashrc file
  238. RUN ln -sfv /go/src/github.com/docker/docker/.bashrc ~/.bashrc
  239. # Activate bash completion and include Docker's completion if mounted with DOCKER_BASH_COMPLETION_PATH
  240. RUN echo "source /usr/share/bash-completion/bash_completion" >> /etc/bash.bashrc
  241. RUN ln -s /usr/local/completion/bash/docker /etc/bash_completion.d/docker
  242. RUN ldconfig
  243. # This should only install packages that are specifically needed for the dev environment and nothing else
  244. # Do you really need to add another package here? Can it be done in a different build stage?
  245. RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
  246. --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \
  247. apt-get update && apt-get install -y --no-install-recommends \
  248. apparmor \
  249. bash-completion \
  250. bzip2 \
  251. inetutils-ping \
  252. iproute2 \
  253. iptables \
  254. jq \
  255. libcap2-bin \
  256. libnet1 \
  257. libnl-3-200 \
  258. libprotobuf-c1 \
  259. net-tools \
  260. patch \
  261. pigz \
  262. python3-pip \
  263. python3-setuptools \
  264. python3-wheel \
  265. sudo \
  266. thin-provisioning-tools \
  267. uidmap \
  268. vim \
  269. vim-common \
  270. xfsprogs \
  271. xz-utils \
  272. zip \
  273. zstd
  274. # Switch to use iptables instead of nftables (to match the CI hosts)
  275. # TODO use some kind of runtime auto-detection instead if/when nftables is supported (https://github.com/moby/moby/issues/26824)
  276. RUN update-alternatives --set iptables /usr/sbin/iptables-legacy || true \
  277. && update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy || true \
  278. && update-alternatives --set arptables /usr/sbin/arptables-legacy || true
  279. RUN pip3 install yamllint==1.26.1
  280. COPY --from=dockercli /build/ /usr/local/cli
  281. COPY --from=frozen-images /build/ /docker-frozen-images
  282. COPY --from=swagger /build/ /usr/local/bin/
  283. COPY --from=tomll /build/ /usr/local/bin/
  284. COPY --from=tini /build/ /usr/local/bin/
  285. COPY --from=registry /build/ /usr/local/bin/
  286. COPY --from=criu /build/ /usr/local/bin/
  287. COPY --from=vndr /build/ /usr/local/bin/
  288. COPY --from=gotestsum /build/ /usr/local/bin/
  289. COPY --from=golangci_lint /build/ /usr/local/bin/
  290. COPY --from=shfmt /build/ /usr/local/bin/
  291. COPY --from=runc /build/ /usr/local/bin/
  292. COPY --from=containerd /build/ /usr/local/bin/
  293. COPY --from=rootlesskit /build/ /usr/local/bin/
  294. COPY --from=vpnkit /build/ /usr/local/bin/
  295. ENV PATH=/usr/local/cli:$PATH
  296. ARG DOCKER_BUILDTAGS
  297. ENV DOCKER_BUILDTAGS="${DOCKER_BUILDTAGS}"
  298. WORKDIR /go/src/github.com/docker/docker
  299. VOLUME /var/lib/docker
  300. VOLUME /home/unprivilegeduser/.local/share/docker
  301. # Wrap all commands in the "docker-in-docker" script to allow nested containers
  302. ENTRYPOINT ["hack/dind"]
  303. FROM dev-systemd-false AS dev-systemd-true
  304. RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
  305. --mount=type=cache,sharing=locked,id=moby-dev-aptcache,target=/var/cache/apt \
  306. apt-get update && apt-get install -y --no-install-recommends \
  307. dbus \
  308. dbus-user-session \
  309. systemd \
  310. systemd-sysv
  311. RUN mkdir -p hack \
  312. && curl -o hack/dind-systemd https://raw.githubusercontent.com/AkihiroSuda/containerized-systemd/b70bac0daeea120456764248164c21684ade7d0d/docker-entrypoint.sh \
  313. && chmod +x hack/dind-systemd
  314. ENTRYPOINT ["hack/dind-systemd"]
  315. FROM dev-systemd-${SYSTEMD} AS dev
  316. FROM runtime-dev AS binary-base
  317. ARG DOCKER_GITCOMMIT=HEAD
  318. ENV DOCKER_GITCOMMIT=${DOCKER_GITCOMMIT}
  319. ARG VERSION
  320. ENV VERSION=${VERSION}
  321. ARG PLATFORM
  322. ENV PLATFORM=${PLATFORM}
  323. ARG PRODUCT
  324. ENV PRODUCT=${PRODUCT}
  325. ARG DEFAULT_PRODUCT_LICENSE
  326. ENV DEFAULT_PRODUCT_LICENSE=${DEFAULT_PRODUCT_LICENSE}
  327. ARG DOCKER_BUILDTAGS
  328. ENV DOCKER_BUILDTAGS="${DOCKER_BUILDTAGS}"
  329. ENV PREFIX=/build
  330. # TODO: This is here because hack/make.sh binary copies these extras binaries
  331. # from $PATH into the bundles dir.
  332. # It would be nice to handle this in a different way.
  333. COPY --from=tini /build/ /usr/local/bin/
  334. COPY --from=runc /build/ /usr/local/bin/
  335. COPY --from=containerd /build/ /usr/local/bin/
  336. COPY --from=rootlesskit /build/ /usr/local/bin/
  337. COPY --from=vpnkit /build/ /usr/local/bin/
  338. WORKDIR /go/src/github.com/docker/docker
  339. FROM binary-base AS build-binary
  340. RUN --mount=type=cache,target=/root/.cache/go-build \
  341. --mount=type=bind,target=/go/src/github.com/docker/docker \
  342. hack/make.sh binary
  343. FROM binary-base AS build-dynbinary
  344. RUN --mount=type=cache,target=/root/.cache/go-build \
  345. --mount=type=bind,target=/go/src/github.com/docker/docker \
  346. hack/make.sh dynbinary
  347. FROM binary-base AS build-cross
  348. ARG DOCKER_CROSSPLATFORMS
  349. RUN --mount=type=cache,target=/root/.cache/go-build \
  350. --mount=type=bind,target=/go/src/github.com/docker/docker \
  351. --mount=type=tmpfs,target=/go/src/github.com/docker/docker/autogen \
  352. hack/make.sh cross
  353. FROM scratch AS binary
  354. COPY --from=build-binary /build/bundles/ /
  355. FROM scratch AS dynbinary
  356. COPY --from=build-dynbinary /build/bundles/ /
  357. FROM scratch AS cross
  358. COPY --from=build-cross /build/bundles/ /
  359. FROM dev AS final
  360. COPY . /go/src/github.com/docker/docker