Member-only story

Docker Commands — Part 3

Meghasharmaa
11 min readFeb 16, 2024

👉 docker container restart: To restart a Docker container, you can use the docker restart command. This command stops and then starts an already running container.

docker restart CONTAINER [CONTAINER NAME]
  • CONTAINER [CONTAINER...]: This is the name or ID of the container(s) you want to restart.

For example, to restart a container named my_container, you would run:

docker restart my_container

If you have multiple containers you want to restart, you can specify their names or IDs separated by spaces:

docker restart container1 container2 container3

This will stop and then start all specified containers. It’s worth noting that the docker restart command is not supported for Swarm services. If you're using Docker Swarm, you should use the docker service update command to update a service, which includes restarting its containers if necessary.

To restart all containers on your Docker host, you can use a combination of docker ps -q to get the list of running container IDs and docker restart to restart them.

docker restart $(docker ps -q)

Let’s break down what’s happening here:

  • docker ps -q: This command lists the IDs of all running containers. The -q

--

--

Meghasharmaa
Meghasharmaa

Written by Meghasharmaa

DevOps Architect | AWS | Docker | Kubernetes | Terraform | Google Cloud | Python

No responses yet