Docker quirks
I noticed a few weird things in the way we use Docker in this project:
- We send the whole project folder as build context, including
.git
and all previously built files and caches, but we only need thepackage.json
file. - We try to execute
/bin/bash
by default, to get a running shell, but thenode
image does not have Bash. - There is a comment in the
Dockerfile
that mentions installingyarn
, but that command has been removed because it is already present in thenode
base image. - Our
Makefile
"targets"build
,compile
andserver
always print a confusing message and try to stop a container that is usually not running anyway. - All
docker run
commands expose port 8000 but only the server needs it. - The Makefile has a missing and a mismatching
.PHONY
target.
Fixes:
- Use
.dockerignore
to reduce the build context from 100 MiB to 5 KiB. - The
node
image has an entrypoint script, so we should pass/bin/sh
to it to run a shell by default. - Rewrite the comment.
- Use the
--rm
parameter to automatically remove containers that have stopped and only stop the running server when starting the server again or when cleaning its files. - Use separate
docker run
arguments for the server. - Add and adjust the
.PHONY
targets.