As a newbie to the tooling, docker-compose it’s great for getting started. To bring up all the service containers with a simple docker-compose up starts everything. However, what if you want to replace an existing container without tearing down the entire suite of containers?
For example: I have a docker-compose project that has the following containers.
Node JS App
I had a small configuration change within the CouchDB container that I wanted to update and re-start to get going but wasn’t sure how to do that.
Here’s how I did it with little down time.
I’m hoping there are better ways to go about this (I’m still learning), but the following steps are what I used to replace a running docker container with the latest build.
Make the necessary change to the container (in my case update the couchdb config).
Run docker-compose build couchdb (docker-compose build <service_name> where service_name is the name of the docker container defined in you’re docker-compose.yml file.)
Once the change has been made and container re-built, we need to get that new container running (without affecting the other containers that were started by docker-compose).
docker-compose stop <service_name> <-- If you want to live on the edge and have the shut-down go faster, try docker-compose kill <service_name>
docker-compose up -d --no-deps <service_name> <-- this brings up the service using the newly built container.
The -d is Detached mode: Run containers in the background, print new container names.
The --no-deps will not start linked services.
That’s it… at least for me, it’s worked to update my running containers with the latest version without tearing down the entire docker-compose set of services.