docker,

How to restart a single container with docker-compose

Jan 22, 2022 · 1 min read · Post a comment
How to restart a single container with docker-compose

Restarting docker-compose stack (docker-compose restart) it’s pretty easy and convinient, and if you somehow screw up something, docker-compose down/up will take care of it. But, now the question is, how can we restart a single docker-compose service running one or multiple containers, without taking down the whole stack.

Prerequisites

  • Docker
  • Docker Compose

Restart a single container without previously applied any changes

docker-compose restart db_service

If you want to add a time to wait before restarting, run:

docker-compose restart -t 10 db_service

Restart a single container with applied changes

docker-compose up --detach --build db_service

or, if you want to apply changes to any service within the docker-compose stack:

docker-compose up --detach --build

Conclusion

As a next step, I would consider deploying docker-compose with zero downtime. It’s possible though without Docker Swarm or Kubernetes, kind of a DIY blue/green deployment.
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.