opsira

Restarting a container is not deploying your code

In short

You change the code, restart the service, and the old behaviour continues. The deploy did not fail. It never happened.

Two different setups, one command

If your source is bind mounted into the container, the running process sees your edits immediately. A restart is enough, and for interpreted code sometimes even that is unnecessary.

If your source is copied in at build time, the image contains a snapshot from whenever it was built. Restarting starts the same image again. Your changes are on disk and nowhere near the process.

The same restart command is correct in one case and useless in the other, which is why this keeps catching people out.

Symptoms

docker compose exec service cat /app/path/to/file.js

Check what the container has, not what the host has. That one command resolves this faster than any amount of reasoning.

The correct action

For a built image you must rebuild, then recreate the container:

docker compose build service
docker compose up -d service

A plain restart does not do this, and neither does up -d on its own if nothing appears to have changed.

Know which is which

Mixed setups are common and are the real trap. A static frontend on a bind mount next to a backend built into an image means half your changes need a rebuild and half do not. Write it down somewhere, or you will guess wrong under pressure.

The bind mount has its own trap: replacing a file rather than editing it in place can leave the container serving the old inode. If a deploy that swaps files appears to have no effect, or starts returning not found, restart the container.

Make it one command

Whatever the right sequence is, put it in a script and always use that. The failure mode here is someone doing the reasonable thing rather than the correct thing, and a script removes the chance to choose.

Need help with any of this?

These notes are free and always will be. If you would rather someone just set it up, or you are stuck on something similar, get in touch at hello@opsira.io.