Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

Restart All or One Service

cd /srv/shop
docker compose restart
docker compose restart web

Run it in the project folder. Without a name, every service of the project restarts; with a name, only that service. Each container is stopped and started again: the same container, the same settings, the same image. On old installations the command was written docker-compose restart.

A restart briefly takes the service offline. Restarting all services of a busy project at once also restarts its database, so name the service you mean.

Why Your Change Did Not Apply

A container's settings are fixed when it is created. restart does not create anything, so edits to ports, volumes, environment variables, or the image tag are ignored. Docker's documentation for the command says so for changes to the compose file and to environment variables. Use up -d instead: Compose compares the file with the running containers and recreates those whose configuration changed, leaving the rest alone.

docker compose up -d

Which Command for Which Change

You changedRun
Nothing, app is stuckrestart web
compose.yamlup -d
The .env or env fileup -d
Image tag or new pullpull, then up -d
Dockerfile or sourceup -d --build
A bind-mounted configrestart web

Every command in the table starts with docker compose. A configuration file mounted from the server is read again when the program starts, so a restart is enough for it. Many programs can also reload their configuration without a restart, for example docker compose exec web nginx -s reload after you test the file with docker compose exec web nginx -t.

Environment Files

Two kinds of files are easy to mix up. The .env file in the project folder fills in ${VARIABLE} placeholders in compose.yaml. A file named under env_file: passes its variables into the container. After editing either one, run docker compose up -d; a restart keeps the old values. To see the final configuration Compose will use, with all values filled in, run docker compose config. That output can contain passwords, so do not paste it anywhere public.

Force a New Container

docker compose up -d --force-recreate web
docker compose up -d --no-deps web

--force-recreate replaces the container even when Compose sees no change, which helps when a container is in a bad state. --no-deps does not start the services that web depends on. Data in named volumes and bind mounts survives a recreate; files written inside the container's own file system do not. Updating images safely is covered in how to update a Docker container.

Give Slow Services More Time

docker compose restart -t 60 db

By default, Compose waits 10 seconds for a container to stop before it kills it. A database writing to disk may need longer.

Check the Result

docker compose ps
docker compose logs -f --tail 50 web

ps shows the state of each service; a service that is restarting over and over shows it here. The logs show why. More options are in docker logs.

After a Reboot

Compose does not run as a service of its own. Containers come back after a reboot because of their restart policy, set with restart: unless-stopped in compose.yaml, and because the Docker service is enabled at boot. See Docker restart policies.

Was this answer helpful?
Loading...