Creation of new container when there is update in docker compose file

Whenever I make changes to the Docker Compose file, the steps I follow are:

  1. Stop the container:: docker stop
  2. Update docker compose file
  3. again start container: docker compose up -d

From my understanding, this process recreates the container and destroys the existing one.

Question:

  1. Is my understanding correct?
  2. If yes, is there a way to reuse the same container, even after modifying the Docker Compose file?

You can just update the compose file and run compose up again. It will only re-create the container if the config for it was changed.

I’m general deleting containers is normal, that’s how they are usually handled, they are not VMs. If you need to persist data, you can use bind mounts or volumes.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.