When running docker-compose up -d
on Windows, Docker automatically configures containers to restart unless explicitly told otherwise. This behavior stems from Docker's default restart policy
being set to unless-stopped
in many cases.
The most maintainable approach is to specify the restart policy in your docker-compose.yml
:
version: '3.8'
services:
your_service:
image: your_image
restart: "no" # Explicitly disable auto-restart
For already running containers, use this Docker command:
docker update --restart=no container_name_or_id
To modify Docker's global behavior on Windows:
# Edit the Docker daemon configuration
{
"restart": false
}
Then restart the Docker service:
Restart-Service Docker
Check a container's restart policy with:
docker inspect -f "{{ .HostConfig.RestartPolicy.Name }}" container_name
Should return no
for disabled containers.
Watch out for:
- Systemd configurations that might override Docker settings
- Windows Task Scheduler auto-starting Docker containers
- Group Policy enforcing certain restart behaviors
When working with Docker on Windows 10/11, containers launched via docker-compose up -d
will automatically restart after system reboot due to Docker's default restart policy. This behavior stems from the implicit restart: unless-stopped
setting in Docker Compose.
The most straightforward solution is to modify your docker-compose.yml
to explicitly set the restart policy:
version: '3.8'
services:
webapp:
image: nginx:latest
restart: "no" # Critical setting to prevent auto-start
ports:
- "80:80"
For existing containers or when you need more control:
Method 1: Update running containers
docker update --restart=no container_name
Method 2: Create containers with explicit policy
docker run -d --restart=no nginx:latest
For complete control over Docker's startup behavior in Windows:
- Open Services management console (
services.msc
) - Locate "Docker Desktop Service"
- Set startup type to "Manual" instead of "Automatic"
After making changes, verify using:
docker inspect --format='{{.HostConfig.RestartPolicy.Name}}' container_name
Should return no
for containers with disabled auto-restart.
If using Docker Swarm mode, you'll need to specify the restart policy in your service definition:
docker service create \
--name myservice \
--restart-condition none \
nginx:latest