docker compose restart command
The docker compose restart command is used to restart one or more services.
The docker compose restart command stops the running service containers and then starts them again.
If you need to update the configuration or just want to simply restart a service without rebuilding the container, restart is very useful.
Syntax
docker compose restart [SERVICE...]
- SERVICE(Optional): You can specify one or more service names to restart. If no service name is specified, all services defined in the docker-compose.yml file will be restarted.
Example
1. Restart all services:
docker-compose restart
2. Restart specific services (for example, services named web and db):
docker-compose restart web db
Make sure you run these commands in the directory containing the docker-compose.yml file, or specify the location of the docker-compose.yml file with the -f argument. For example, if your docker-compose.yml file is not in the current directory, you can specify the file location like this:
docker-compose -f /path/to/docker-compose.yml restart
This lets you control which docker-compose.yml file is used to manage services.
Docker Command Reference