Testing website docker images built from Dockerfiles

Each of our website projects has a Dockerfile in the root of the project, which should build website image that we run in staging and production.

ⓘ This is completely unrelated to the tooling for local development (./run or dotrun). Changes in the Dockerfile will not effect local development at all.

Building and running website images

You can build these images yourself pretty simply. The first step is to set the DOCKER_BUILDKIT=1 environment variable, which I suggest you do in your .bashrc:

echo "export DOCKER_BUILDKIT=1" > ~/.bashrc
source ~/.bashrc

Now you can build the image, from the root of the codebase, with the following command:

docker build --tag mywebsite --build-arg BUILD_ID=test-build .

ⓘ Both the tag and build-arg are optional. The tag is so we can easily refer to the image for running it later (otherwise you’ll have to use the generated image hash). The build-arg gets output in the X-VCS-Revision HTTP header returned by the website.

You can run the image as follows using the tag for the image you just built, and a random port:

docker run -ti --publish 8777:80 mywebsite

This will run the website image, and attach the server (on port 80 inside the image) to port 8777 on localhost. You should now be able to visit http://localhost:8777 to see the built site running.

Running images built for production

You can also pull down and test out the images that get built and released to our production websites by our Jenkins jobs.

Our staging jobs ({domain}-staging) build the images that are the ultimately released to production by our production jobs ({domain}-production). You can see the image name in the log output of staging and production jobs for our websites. E.g. at the end of a build of a ubuntu.com-staging run:

########################################
# Success: Wait for deployment/ubuntu-com-tutorials to succeed
########################################


===
Image: prod-comms.docker-registry.canonical.com/ubuntu.com:1585056794-151c5a3
Deployed to https://staging.ubuntu.com

To download and run this image, you first have to be logged in to the canonical Docker registry - if you need credentials for this ask one of the more infrastructure-focused developers:

docker login prod-comms.docker-registry.canonical.com

Now you can download and run the image exactly as before, but using the image name from the build, e.g.:

docker run -ti --publish 8777:80 prod-comms.docker-registry.canonical.com/ubuntu.com:1585056794-151c5a3

Again, go to http://localhost:8777 to see the running site.