This page is primarily for my benefit, but hopefully somebody else will find it useful as well!
I always like sharing what I do with other people. That’s part of what I love about the internet. Thus, I try to make my Dockerfiles reusable by anyone. I also don’t want to include anything in my Dockerfiles that I would consider sensitive or overly site-specific, like paths to my data volumes. Here are some tips on making release-ready Dockerfiles.
One of the easiest ways to make a Dockerfile easy to customize is to build a shell script for building and running the container. The commands you’d use are discussed below, but here is a template for you to start:
In your READMEs, you can easily instruct your users to configure the container with simple commands like
echo PORT=2368 >> ./container.cfg
Let’s face it, development and deployment are two very different beasts. For development, I typically make sure that the base container image (with no volumes mounted) has everything necessary to play around. This is also useful for writing integration testing scripts, because they can start from a clean slate each time.
Since I use data volumes copiously (see below), I have never really found myself reusing containers. I will usually make a shell script that collects the most common actions for my particular project.
Often you will find yourself in need of a self-signed certificate as a part of your base image. I discovered that you can do this noninteractively with one command:
RUN openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -subj '/CN=localhost' -days 365
This is not something you want to serve publicly, of course, but it is a great one-liner nevertheless.