Reputation: 27486
I've got a docker image that contains a number of services. I've been thinking about using Docker Compose to build this image, instead of packaging everything inside one great big image.
What I'm having trouble with is the strategy for applying changes to the services with different versions of the main image. For example, one of the services is a postgres database, and sometimes the schema may change. When I'm deploying a single monolithic image, I know exactly what version of the schema a user will get when they pull a specific version of the image. I'm not sure what will happen if I use docker compose. When the user starts the new version of my image, will it always start with a clean postgres container, or will it reuse the existing container?
I can think of situations when reusing would be useful (such as if the host machine goes down and I don't want the database to be lost), but if they pull a new image, I'd want to know for certain that they get a clean container and that my main container can run the initial DDL/DML scripts to prepare it properly. Is this even a valid concern?
Upvotes: 2
Views: 1031
Reputation: 8791
From the Documentation about the docker-compose up command :
By default, if there are existing containers for a service, docker-compose up will stop and recreate them (preserving mounted volumes with volumes-from), so that changes in docker-compose.yml are picked up. If you do not want containers stopped and recreated, use docker-compose up --no-recreate. This will still start any stopped containers, if needed.
So to go deeper in your application.
Using docker-compose up
command when you want to update the image and want the database into your container to be dropped for fresh container.
Using docker-compose up --no-recreate
will not re create container that weren't updated. Use it when you want to update but don't need to recreate all auxiliary container.
Putting a restart:always
in the description of your container in the docker-compose.yml will ensure the Docker daemon will restart the container if it stop.
Upvotes: 3