Skip to content

Commit da8f6f5

Browse files
committed
minor #15943 Local development Docker improvements (hiddewie)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- Local development Docker improvements When building the local development Docker image, a huge context is sent to the Docker daemon. Even worse, the whole image is usually rebuilt instead of Docker layer caching reusing the previous builds of the same image. Example output ``` ~/C/G/symfony-docs (request-locales|✔) $ docker build . -t symfony-docs Sending build context to Docker daemon 164.4MB Step 1/8 : FROM python:2-stretch as builder 2-stretch: Pulling from library/python 7568c21980bd: Pull complete 4a9f2207c812: Pull complete 6fe350d2b140: Pull complete d95a2fdc8b3d: Pull complete # ... ``` The problem is 2 things - a locally built `_build` directory is sent with the Docker context - The `.git` directory is sent with the Docker context Both are not needed in the build process. This has been fixed with a `.dockerignore` file, see the documentation here: https://docs.docker.com/engine/reference/builder/#dockerignore-file New output: ``` ~/C/G/symfony-docs (docker-performance|✔) $ docker build . -t symfony-docs Sending build context to Docker daemon 12.88MB Step 1/9 : FROM python:2-alpine as builder 2-alpine: Pulling from library/python aad63a933944: Already exists 259d822268fb: Already exists # ... ``` Next, the much smaller `alpine` variants of the base images can be used, which is smaller to download. The Python 2 and Nginx base image both have an alpine variant. Commits ------- 8dd11f1 Local development Docker improvements
2 parents 9afe27f + 8dd11f1 commit da8f6f5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.git
2+
/_build/doctrees
3+
/_build/spelling
4+
/_build/html
5+
/_build/logs.txt
6+
/_build/vendor
7+
/_build/output
8+
*.pyc

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
FROM python:2-stretch as builder
1+
FROM python:2-alpine as builder
22

33
WORKDIR /www
44

55
COPY ./_build/.requirements.txt _build/
66

7-
RUN pip install pip==9.0.1 wheel==0.29.0 \
7+
RUN apk add \
8+
git \
9+
make
10+
11+
RUN pip install pip==9.0.1 wheel==0.29.0 \
812
&& pip install -r _build/.requirements.txt
913

1014
COPY . /www
1115

1216
RUN make -C _build html
1317

14-
FROM nginx:latest
18+
FROM nginx:alpine
1519

1620
COPY --from=builder /www/_build/html /usr/share/nginx/html

0 commit comments

Comments
 (0)