1

I am working at a micro-service application and there are multiple services. I am using docker-compose to run instances of different micro services. We create an image for every micro service. If I change the code of a micro-service, I use 'docker-compose down' then changing the version of updated micro service and then use 'docker-compose up'. I think, there should be a way to update the image at run time without using 'docker-compose down' and 'docker-compose up'.

Is there and way to replace image of running container with docker-compose?

user3082820
  • 91
  • 2
  • 8
  • I think, this could help you. [Upgrade docker container](https://stackoverflow.com/questions/26734402/how-to-upgrade-docker-container-after-its-image-changed) and [docker compose in production](https://docs.docker.com/compose/production/#deploying-changes). – JTejedor Oct 12 '20 at 08:04
  • Have you tried Kubernetes? – jtlz2 Oct 12 '20 at 08:20

1 Answers1

3

You can skip docker-compose down. The docker-compose up command will recreate the container if the image has been built or pulled since it was last started. See this answer for more details and an example of this in action.

You cannot hot swap the image from within a running container. That's equivalent to replacing the root hard drive while a Linux OS is running. It would break things, particularly anything with an open file handle.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • Kubernetes could do it, so how about Docker swarm..? – jtlz2 Oct 12 '20 at 08:20
  • 1
    @jtlz2 Kubernetes doesn't do it, it replaces the containers, same as docker-compose and Swarm Mode. Look at how ReplicaSet and Deployment are used to perform a rolling update. – BMitch Oct 12 '20 at 08:22