Stupid Docker Build Tricks

Cats rode around on Roombas in GoDaddy’s Super Bowl commercial. Via GoDaddy/YouTube

The other day I was playing around with Docker Build

One of the exercises in a video I was watching wanted me to copy the source code for a simple Python App into the build directory and then use the COPY command in the Dockerfile to pull it into the Docker Image that was being built.

And I thought to myself… I don’t like things being static.

Why not use a git clone to pull the source code directly from GitHub?

So I tried it…

FROM ubuntu

RUN apt-get update
RUN apt-get install -y python python-pip git
RUN pip install flask
RUN git clone

ENTRYPOINT FLASK_APP=/simple-webapp-flask/ flask run --host=

And it Worked!!!

But then I got to thinking… If we can do a git clone as part of the Docker Build process, WHY would they include a COPY command?

Wouldn’t we always want the latest and greatest?

Well… Yeah… But if we used the git clone command to pull the source into the Docker Image, every Docker Image that we build would have the Git package installed.

That kinda goes counter to the goal of keeping Containers lightweight.

Using git clone would also mean that you’re always going to use the latest commit in your build… Which might not be the one that you actually want.

It would be better to use something else to pull the current source code into the build directory and then start the build.

That way the extra overhead is kept on the system that’s being used to build the Docker Image and not carried along with it to each Docker host.

Leave a Reply

Your email address will not be published. Required fields are marked *