Docker development workflow for compiled components in a docker-compose setup Docker development workflow for compiled components in a docker-compose setup docker docker

Docker development workflow for compiled components in a docker-compose setup


I would do this:

Run docker-compose up but:

  • use a host volume for the directory of the compiled binary instead of the source
  • use an entrypoint that does something like

entrypoint.sh:

trap "pkill -f the_binary_name" SIGHUPtrap "exit" SIGTERMwhile [[ 1 ]]; do  ./the_binary_name;done

Write a script to rebuild the binary, and copy it into the volume used by the service in docker-compose.yml:

# Run a container to compile and build the binarydocker run -ti -v $SOURCE:/path -v $DEST:/target some_image build_the_binary# copy it to the host volume directorycopy $DEST/... /volume/shared/with/running/container# signal the containerdocker kill -s SIGHUP container_name

So to compile the binary you use this script, which mounts the source and a destination directory as volumes. You could skip the copy step if the $DEST is the same as the volume directory shared with the "run" container. Finally the script will signal the running container to have it kill the old process (which was running the old binary) and start the new one.

If the shared volume is making compiling in a container too slow, you could also run the compile on the host and just do the copy and signaling to have it run in a container.

This solution has the added benefit that your "runtime" image doesn't need all the dev dependencies. It could be a very lean image with just a bare OS base.