Skip to content

Docker quirks

I noticed a few weird things in the way we use Docker in this project:

  1. We send the whole project folder as build context, including .git and all previously built files and caches, but we only need the package.json file.
  2. We try to execute /bin/bash by default, to get a running shell, but the node image does not have Bash.
  3. There is a comment in the Dockerfile that mentions installing yarn, but that command has been removed because it is already present in the node base image.
  4. Our Makefile "targets" build, compile and server always print a confusing message and try to stop a container that is usually not running anyway.
  5. All docker run commands expose port 8000 but only the server needs it.
  6. The Makefile has a missing and a mismatching .PHONY target.

Fixes:

  1. Use .dockerignore to reduce the build context from 100 MiB to 5 KiB.
  2. The node image has an entrypoint script, so we should pass /bin/sh to it to run a shell by default.
  3. Rewrite the comment.
  4. 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.
  5. Use separate docker run arguments for the server.
  6. Add and adjust the .PHONY targets.