My Docker setup for a quick start
April 9th, 2021
On the occasion of starting yet another project, hoping it’ll actually get released one day, I wanted to share my Docker configuration which I use for quickly orchestrating different stacks together.
It’s nothing fancy, there are likely better ways to do it, however my usual setup is enough for:
- Quickly setting up different services
- Maintaining fully reproducible environments from the start (tear down and rebuild every second day)
- Separating day-to-day work files from build files
- Quickly adjusting the structure for new ideas and needs
Overview
# Build and initial configuration files
docker/
# Build files per service
service-a/
Dockerfile.dev
Dockerfile.prod
# Env variables per service
.env.example
# Build-step files and directories
vol/
servers.json
# Services configuration for each environment
compose.dev.yml
compose.prod.yml
# Day-to-day work files
src/
service-a/
About Dockerfile.[dev|prod]
Differences between Dockerfile.dev
and Dockerfile.prod
? During development you may want to include a debugger, run an empty
container with tail -f /dev/null
or just include
a different base image. While this distinction introduces code duplication, it’s
clear how many different target environments your project supports, at least
within the context of Docker. In more complicated scenarios however, with bigger
files, they can be merged into one, with multiple stages and conditional logic
based on arguments/environment configuration.
About top-level src
The top-level src
directory and it’s subdirectories
is what is mapped via compose.[dev|prod].yml
files.
These directories are mounted as volumes, and I usually use dev containers plugin
for Visual Studio Code to jump into them and work with full support of given
container’s technology and scope, at the same time keeping my editor’s local
configuration and preferences.