Repository navigation
Open
Description
- This is a bug report
- This is a feature request
- I searched existing issues before opening this one
Expected behavior
Launching a container with --restart=unless-stopped should restart the container when the daemon reloads.
Actual behavior
Containers are not restarted. The docs say they will be restarted unless they are stopped first, but restarting the daemon doesn't imply changing any containers to the 'stopped' state. (e.g. in my case I just upgraded Docker, and the docker CLI couldn't communicate with the still-running old daemon version, so I wanted to restart the daemon. Doing so allowed the CLI to communicate with it again, but all my containers disappeared.)
Steps to reproduce the behavior
docker run --restart=unless-stopped example
systemctl restart docker
docker ps
# 'example' container did not restart
Output of docker version:
$ docker version
Client:
Version: 18.09.5-ce
API version: 1.39
Go version: go1.12.3
Git commit: e8ff056dbc
Built: Fri Apr 12 08:22:13 2019
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.09.5-ce
API version: 1.39 (minimum version 1.12)
Go version: go1.12.3
Git commit: e8ff056dbc
Built: Fri Apr 12 08:21:24 2019
OS/Arch: linux/amd64
Experimental: false
Output of docker info:
$ docker info
Containers: 4
Running: 1
Paused: 0
Stopped: 3
Images: 377
Server Version: 18.09.5-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb.m
runc version: 69ae5da6afdcaaf38285a10b36f362e41cb298d6
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.18.16-arch1-1-ARCH
Operating System: Arch Linux
OSType: linux
Architecture: x86_64
CPUs: 32
Total Memory: 62.84GiB
Name: vorticon
ID: EZCR:W6J4:DZ5L:AWQP:TLBM:UCHG:GPWO:C2R4:JQDA:BUOL:WYQU:KY46
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Reacted by Andrey, saintech, Gimiki, seb, Notas Hellout, Adam Romanek, Brian Kendzior, Arne Groskurth, James Firth, Patrick Cudahy and 8 more
Metadata
Metadata
Assignees
Labels
No labels
Activity
VinayKumarKnol commentedon May 4, 2019
@Malvineous If your docker container got killed while you
docker run examplethen, in that case, the restart policy won't actually restart your container since it is already has been killed before you restarted the daemon. From the doc,Always restart the container regardless of the exit status, including on daemon startup, _except if the container was put into a stopped state_ before the Docker daemon was stopped.As a suggestion, You should see the output of
docker psjust after you run your containerdocker run --restart=unless-stopped exampleMalvineous commentedon May 4, 2019
The Docker container does not get killed, it runs successfully for many days after starting it. The machine can reboot and the container will come up again after rebooting (or at least it did the last time I rebooted, which was on an earlier Docker version.)
Now, like I said in the 'steps to reproduce' above, the container starts successfully and can again run for many days, however once you restart the Docker daemon with
systemctl(without stopping the container yourself), it doesn't come back when Docker restarts.--restart=unless-stoppedsuggests that the container will restart so long as you don't stop the container withdocker stop, which I have not done.Jangor67 commentedon May 7, 2019
I have the same problem. After upgrading from older version to 18.09.1 containers that were running up to the moment the system is rebooted are not started after system reboot.
As a workaround i changed the restart policy (docker update --restart=always:0 my-container) which works for me but it would be nice if this bug can be solved!
Chakiral commentedon Sep 25, 2019
I have the same problem here, on Docker CE 19.03.2
The workaround mentioned by @Jangor67 is for the moment our solution, put the container as "restart always"
MastaG commentedon Oct 3, 2019
I think when you reboot, systemd will stop the docker service, which in turn takes care of stopping all containers.
Perhaps that's why the container will have the "stopped" exit status and not get started when the docker service starts again after a reboot.
Malvineous commentedon Oct 3, 2019
This might be the case, but then the bug is that when Docker is being shut down, it also marks all the containers as stopped even though the user did not request the containers be stopped. The containers should only be marked as stopped when
docker stopis run.markgoddard commentedon Oct 24, 2019
I hit a similar issue to this. The cause ended up being using
docker kill --signal HUP <container>, which Docker assumes will stop the container and marks it as not being restartable. I don't see that in your reproduction steps though, so could be a different issue.Docker 19.03.4, CentOS 7.6
Malvineous commentedon Oct 24, 2019
@markgoddard Using
docker killimplies you want the container stopped, so--restart=unless-stoppedwould appear to make sense there. (Otherwise you would use--restart=alwaysand then the container would be restarted immediately after you randocker kill).In the case of this bug, we haven't stopped the containers (just rebooted the system) but Docker is acting as if we have requested each container be permanently stopped, when we haven't made such a request.
markgoddard commentedon Oct 24, 2019
I'm using SIGHUP, which doesn't typically kill a process. I found an old docker bug about the issue: moby/moby#11065. Thanks for replying.
yshaban-godaddy commentedon May 15, 2020
Having the same issue on Cent 7, Docker version 19.03.8.
nyetwurk commentedon Sep 16, 2020
Having this issue with Ubuntu 18.04 on system reboot. Some containers restart, some don't.
PostImpatica commentedon Oct 22, 2020
I know this issue isn't related to windows but just wanted to say since this article pulls up when searching this issue on Google that I also have the issue when our Windows Server 2016 server gets rebooted.
gimiki commentedon Nov 8, 2020
+1
on Ubuntu 20.04 armhf with docker.io package
As a workaround I switched to docker-ce package from 18.04 repository (because armhf has no release candidate in the 20.04 repository as per #1035)
StarWitch commentedon Dec 23, 2020
Also receiving this issue on an Ubuntu 20.04 VM running inside ESXi, using
docker.io.I tried upgrading to
docker-ce, as mentioned by @gimiki, using this official guide, and suddenly the problem was fixed: containers restart on reboot without further input.I'm noticing this guide specifically says
Older versions of Docker were called docker, docker.io, or docker-engine. If these are installed, uninstall them. Does this mean thedocker.iopackage in the Ubuntu repositories is no longer supported, and usingdocker-ceis now the preferred method for installing Docker on Ubuntu?If so, perhaps the
docker.iopackage should be marked as deprecated, or some effort should be made to bringdocker-ceinto the mainline Ubuntu repositories.tobia commentedon Mar 9, 2021
Thank you, this solved a problem I was having too. I use docker kill -sHUP to reload the configuration of a daemon, but I didn't realize it would cause Docker to assume the container should be in a stopped state!
dcrousset commentedon May 7, 2021
While waiting for a fix, here is a workaround that doesn't break the restart policy
Enjoy :o)
RebelSoftware commentedon May 15, 2023
I found this bug while researching a similar issue.
Containers set to restart (via docker compose) "unless-stopped" not restarting when the docker daemon reloads.
Twice now I have had the docker daemon abruptly exit due to a nil pointer condition, while I haven't been able to find a reason for that I was surprised that my containers were not coming back up when the daemon managed to restart.
I would have thought that the daemon failing for whatever reason would have resulted in the containers all being restarted.
as a bandaid I have set all my containers to a restart policy of "always"
ShojibFlamon commentedon Oct 25, 2024
Check from here in details Docker Restart Policy
LightningRhino commentedon Nov 17, 2024
I have a similar problem.
Only those containers where I have configured a different logging driver in the docker-compose.yml (here: splunk) won't start after reboot, no matter if "restart: always" or "restart: unless-stopped" is specified.
Bug or feature?
alexzouiten commentedon Feb 19, 2025
Similar issue here. I have a docker compose with multiple services, all using the
restart=unless-stoppedpolicy. For some reason one of them doesn't restart randomly when docker daemon is started.readmodifywrite commentedon Aug 15, 2025
Ran into this today, really appreciate the comments here, y'all helped me fix what was going on.
Super annoying that this has been open since 2019 with no actual fix. This is totally braindead behavior: kill does NOT mean an application is terminating, it just sends signals, and one of those signals happens to mean stop the program, and the others don't. Docker should not be marking the container as manually stopped on a kill, only on an actual stop command.
Also nice to see Docker has known about this since 2015 and just closed it as if it were fixed, even though it definitely is not.
It also doesn't help that there is no log activity that shows this is what is happening. You won't know about this until you run into it and then hopefully you'll find your way here. If that is you: welcome to yet another exclusive club of people whacked by a bug that no one will ever fix. Just use restart always, or find some other way to send signals to your containers.
7-zete-7 commentedon Nov 19, 2025
I’ve recently started encountering the same issue. In my case, Docker tries to restart containers after a daemon restart, but if the first attempt fails, it doesn’t retry.
Since I couldn’t find any details in this thread on how to diagnose why a container fails to start after a Docker restart, I wanted to share a tip that helped me. You can check
State.Errorof a container to see the reason it didn’t start:docker inspect -f "{{.State.Error}}" <container>This can provide useful information about why the container failed to come up.
diogovalada commentedon Oct 29, 2026
For the daemon-crash case described in #652 (comment) (dockerd exits abruptly and
unless-stoppedcontainers do not come back):The cause is in the daemon's restore path. With live-restore off, the new daemon stops the containers that survived the crash, and that stop marks them as manually stopped, so
unless-stoppedno longer restarts them. A clean daemon restart is not affected.I've filed it in moby/moby with code references and a reproduction: moby/moby#54065
Workarounds until it is fixed:
--restart always, or enablelive-restore.