Creating a Minimal Docker Container

This is a minimal Docker Container, based on Alpine Linux, that automatically launches a shell. You can use it to run experiments that will help you build a more complex docker container.

It’s a base container that I’ll spin up often in order to figure out the specific commands I need to run to install packages, manually configure things, and otherwise experiment with Alpine Linux. Once I’ve figured things out I’ll write those commands into a new Dockerfile to create a more permanent image.

This will be my starting point for a lot of future work.

Today I’m starting a business doing technical writing. This is my first article. I’ve been writing on this blog for a long time but I don’t think I’ve thought about my writing as a business in itself. I typically write notes for my future self. My plan, now, is to weave a little bit of personal story into each article.

I really got the idea while reading the book The Art and Business of Online Writing by Nicolas Cole. Cole created a career out of writing answers and studying what worked well on the Quora platform.

In his book he talks about writing every single day. Stephen King suggests daily writing in his book On Writing and I’ve sure I’ve heard the advice in lots of other places. But, I don’t think I’ve ever really tried daily writing.

Here’s the minimal Dockerfile.

FROM alpine:latest

CMD ["sh"]

Save this file in a directory with the filename Dockerfile (no extension).

Run the following command to build an image based on this Dockerfile.

docker build --tag alpine-shell .

Run the following command to run a container using the image you built above.

docker run -it --rm alpine-shell

The -it switch runs the container with an interactive shell. The -rm switch will automatically delete it when you exit. I use that because I want my work inside the container to be temporary. I’ll add the commands to the Dockerfile as I figure them out. For example, I might run apk add git to install git in the container. If that works I’ll add the RUN command to my Dockerfile.

RUN apk add git

Creating a Dockefile based on Alpine creates an image that is about 8MB in size.

Written by Joel Dare on October 15, 2024.