Skip to content

Commit d68be71

Browse files
committedNov 26, 2014
Optimize Dockerfile.
This optimizes the Dockerfile by; - Combining RUN statements so that files are removed in the same layer as they are added. - Removing the downloaded .tar.gz of the docker-gen binary after expanding - Adding `--no-install-recommends` (but explicitly installing ca-certificates) - Replacing `ADD` with `COPY` (recommended if no unpacking is required) Also added a `.dockerignore` file to prevent the `.git` directory and README.md being added to the image. These changes reduce the size of the image with 34 MB (was 268.4 MB, now 233.9 MB), and results in less layers being produced. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent a912287 commit d68be71

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed
 

‎.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git
2+
README.md

‎Dockerfile

+24-18
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,34 @@ FROM ubuntu:14.04
22
MAINTAINER Jason Wilder jwilder@litl.com
33

44
# Install Nginx.
5-
RUN echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu trusty main" > /etc/apt/sources.list.d/nginx-stable-trusty.list
6-
RUN echo "deb-src http://ppa.launchpad.net/nginx/stable/ubuntu trusty main" >> /etc/apt/sources.list.d/nginx-stable-trusty.list
7-
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
8-
RUN apt-get update
9-
RUN apt-get install --only-upgrade bash
10-
RUN apt-get install -y wget nginx
5+
RUN echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu trusty main" > /etc/apt/sources.list.d/nginx-stable-trusty.list \
6+
&& echo "deb-src http://ppa.launchpad.net/nginx/stable/ubuntu trusty main" >> /etc/apt/sources.list.d/nginx-stable-trusty.list \
7+
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C \
8+
&& apt-get update \
9+
&& apt-get install -y -q --no-install-recommends \
10+
ca-certificates \
11+
nginx \
12+
wget \
13+
&& apt-get clean \
14+
&& rm -r /var/lib/apt/lists/*
15+
16+
# Configure Nginx and apply fix for long server names
17+
RUN echo "daemon off;" >> /etc/nginx/nginx.conf \
18+
&& sed -i 's/# server_names_hash_bucket/server_names_hash_bucket/g' /etc/nginx/nginx.conf
19+
20+
# Install Forego
21+
RUN wget -P /usr/local/bin https://godist.herokuapp.com/projects/ddollar/forego/releases/current/linux-amd64/forego \
22+
&& chmod u+x /usr/local/bin/forego
1123

12-
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
13-
14-
#fix for long server names
15-
RUN sed -i 's/# server_names_hash_bucket/server_names_hash_bucket/g' /etc/nginx/nginx.conf
24+
ENV DOCKER_GEN_VERSION 0.3.4
1625

17-
RUN wget -P /usr/local/bin https://godist.herokuapp.com/projects/ddollar/forego/releases/current/linux-amd64/forego
18-
RUN chmod u+x /usr/local/bin/forego
26+
RUN wget https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/docker-gen-linux-amd64-$DOCKER_GEN_VERSION.tar.gz \
27+
&& tar -C /usr/local/bin -xvzf docker-gen-linux-amd64-$DOCKER_GEN_VERSION.tar.gz \
28+
&& rm /docker-gen-linux-amd64-$DOCKER_GEN_VERSION.tar.gz
1929

20-
ENV DOCKER_GEN_VERSION 0.3.4
21-
RUN wget https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/docker-gen-linux-amd64-$DOCKER_GEN_VERSION.tar.gz
22-
RUN tar -C /usr/local/bin -xvzf docker-gen-linux-amd64-$DOCKER_GEN_VERSION.tar.gz
30+
COPY . /app/
31+
WORKDIR /app/
2332

24-
RUN mkdir /app
25-
WORKDIR /app
26-
ADD . /app
2733

2834
EXPOSE 80
2935
ENV DOCKER_HOST unix:///tmp/docker.sock

0 commit comments

Comments
 (0)
Please sign in to comment.