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
- Redis Cache
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).
docker-compose build couchdb(
docker-compose build <service_name>where
service_nameis the name of the docker container defined in your
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.
-d is Detached mode: Run containers in the background, print new container names.
--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.
Again, if you know of a faster/better way to go about this, I'd love to hear it. Or if you know of any down-sides to this approach, I'd love to hear about it before I have to learn the hard way on a production environment.
Thanks to Vladimir in the comments below - you can skip several steps above and do it with a single command
docker-compose up -d --no-deps --build <service_name>
I tested this and was able to avoid the
up commands with this one-liner.
Happy Container Updating!