SteGriff

Blog

Next & Previous

From dockerfile to running container

Preamble

Five years ago I made a post called Learning to use Docker. That post focused on pulling images from the registry and running them to get going with commodity software. It goes over some of the basic terms like image and container.

Recently I’ve been looking into running my own project in a docker container because it might simplify the “deployment journey”. Firstly, let me imply that I deeply resent this effort and it makes me want to revert to a PHP hacker or perhaps someone who only writes software with VB6 (I’m also considering MacPascal).

I needed a refresher and ended up with a file called Desktop/docker-garbage.txt and it is the expanded version of that file which you are about to read.

Docker Garbage

How do I compile my project into an image?

From the directory where your dockerfile is, you can create a named image using docker build with -t

docker build . -t coolnexus

Now you can see your images

docker images

Now you can run an image by name to make a container

docker run coolnexus

But you probably need to pass env variables like this!:

docker run -e 'SESSION_SECRET=secret-code' coolnexus

# or

docker run --env-file .env coolnexus

You’re welcome 🏝