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
.gitand all previously built files and caches, but we only need thepackage.jsonfile. - We try to execute
/bin/bashby default, to get a running shell, but thenodeimage does not have Bash. - There is a comment in the
Dockerfilethat mentions installingyarn, but that command has been removed because it is already present in thenodebase image. - Our
Makefile"targets"build,compileandserveralways print a confusing message and try to stop a container that is usually not running anyway. - All
docker runcommands expose port 8000 but only the server needs it. - The Makefile has a missing and a mismatching
.PHONYtarget.
Fixes:
- Use
.dockerignoreto reduce the build context from 100 MiB to 5 KiB. - The
nodeimage has an entrypoint script, so we should pass/bin/shto it to run a shell by default. - Rewrite the comment.
- Use the
--rmparameter 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 runarguments for the server. - Add and adjust the
.PHONYtargets.