Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update only one Container via docker-compose

Let's say I have a docker-compose.yml file containg five apps & I started them via docker-compose up -d Now there is an update for one of these apps available which I want to use. So I pull this newer image and... how can I stop this one old container without stopping the four other container?

  • Using docker-compose down && docker-compose up -d would stop and restart all of my container, so that's wrong.
  • Using docker stop app_1 && docker run app_1 would work but seems "wrong" to me because it's no docker-compose command.

So what's the "docker-way" to do this?

like image 673
Munchkin Avatar asked Aug 26 '16 14:08

Munchkin


People also ask

Can you modify the container properties once the container is running?

Danger Zone: Changing Other Container Properties While this option provides a way to arbitarily edit existing containers, it won't work while they're running. Use the docker stop my-container command to stop the container you want to edit, then continue to make your changes. Once you've got to a container's config.

Does Docker compose update?

Docker Compose has a built-in pull command that will pull updated versions of all the images in your stack.


4 Answers

Just run docker-compose up -d again (without down / stop / kill before).

Initial docker-compose.yml:

version: "2"

services:
  db1:
    command: mongod
    image: mongo:3.2.4
    ports:
      - "27020:27017"

  db2:
    command: mongod
    image: mongo:3.2.4
    ports:
      - "27021:27017"

Update db2:

version: "2"

services:
  db1:
    command: mongod
    image: mongo:3.2.4
    ports:
      - "27020:27017"

  db2:
    command: mongod
    image: mongo:3.2.6
    ports:
      - "27021:27017"

Run docker-compose up -d again:

Pulling db2 (mongo:3.2.6)...
3.2.6: Pulling from library/mongo
47994b92ab73: Pull complete
a3ed95caeb02: Pull complete
71b6becd9768: Pull complete
7d5d40f9dc7b: Pull complete
9dc152e647de: Pull complete
3f1f69340f17: Pull complete
82a29b50f1d2: Pull complete
97869c61a050: Pull complete
50aa2bf3bccc: Pull complete
03913f2c5b05: Pull complete
Digest: sha256:29ee114c0ce96494553cd72f18d92935b36778b77bce167fc9962e442d8c7647
Status: Downloaded newer image for mongo:3.2.6
composetest_db1_1 is up-to-date
Recreating composetest_db2_1 

The last two lines of the output show the expected behavior.

like image 173
Alexander Zeitler Avatar answered Oct 17 '22 16:10

Alexander Zeitler


There's one use-case where the accepted answer doesn't work:

Say you have 4 containers, with 2 having a new version, and you only want to update/restart ONE of them.

If you simply do docker-compose up -d again, this will update both containers.

If you want to target only one specific container, you can do it in two steps:

  • Pull all updates: docker-compose pull (this will just download the images, not do anything else)
  • And then only update the container you want: docker-compose up -d --no-deps name_of_your_container

--no-deps is important to avoid restarting dependencies of your updated containers by mistake.

like image 35
Antoine Jaussoin Avatar answered Oct 17 '22 16:10

Antoine Jaussoin


quite old question but the answer does not seem to work if the image has changed on docker hub and we don't change the docker file e.g. if I'm using the latest version of mongo (mongo:latest) in the example above and the "latest" tag is moved in Docker Hub from 3.2.4 to 3.2.6, it is not pulled by only running docker-compose up -d as far as I can see...

like image 42
Olivier Avatar answered Sep 24 '22 04:09

Olivier


To restart only one container you can simply do:

docker-compose up -d --build image-name

The output will look like this:

Recreating image-name ... done
like image 22
Emmanuel Avatar answered Oct 17 '22 16:10

Emmanuel