Skip to content

Commit a53e235

Browse files
committed
Use --link with COPY in Dockerfile
Re-use already built COPY layers in subsequent builds even if the previous layers have changed, which is especially helpful when copying from another build stage. See https://docs.docker.com/engine/reference/builder/#copy---link
1 parent 0db60fc commit a53e235

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# syntax=docker/dockerfile:1
1+
# syntax=docker/dockerfile:1.4
22
FROM buildpack-deps:buster as builder-nsjail
33

44
WORKDIR /nsjail
@@ -29,7 +29,7 @@ RUN apt-get -y update \
2929
tk-dev \
3030
&& rm -rf /var/lib/apt/lists/*
3131

32-
COPY scripts/build_python.sh /
32+
COPY --link scripts/build_python.sh /
3333

3434
# ------------------------------------------------------------------------------
3535
FROM builder-py-base as builder-py-3_11
@@ -55,17 +55,17 @@ RUN apt-get -y update \
5555
libprotobuf17 \
5656
&& rm -rf /var/lib/apt/lists/*
5757

58-
COPY --from=builder-nsjail /nsjail/nsjail /usr/sbin/
59-
COPY --from=builder-py-3_11 /lang/ /lang/
60-
COPY --from=builder-py-3_12 /lang/ /lang/
58+
COPY --link --from=builder-nsjail /nsjail/nsjail /usr/sbin/
59+
COPY --link --from=builder-py-3_11 /lang/ /lang/
60+
COPY --link --from=builder-py-3_12 /lang/ /lang/
6161

6262
RUN chmod +x /usr/sbin/nsjail \
6363
&& ln -s /lang/python/3.11/ /lang/python/default
6464

6565
# ------------------------------------------------------------------------------
6666
FROM base as venv
6767

68-
COPY requirements/ /snekbox/requirements/
68+
COPY --link requirements/ /snekbox/requirements/
6969
WORKDIR /snekbox
7070

7171
RUN pip install -U -r requirements/requirements.pip
@@ -84,7 +84,7 @@ RUN if [ -n "${DEV}" ]; \
8484
fi
8585

8686
# At the end to avoid re-installing dependencies when only a config changes.
87-
COPY config/ /snekbox/config/
87+
COPY --link config/ /snekbox/config/
8888

8989
ENTRYPOINT ["gunicorn"]
9090
CMD ["-c", "config/gunicorn.conf.py"]

0 commit comments

Comments
 (0)