Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

dockerd refuses to start because /var/run/docker.pid points at a live process

Your error

failed to start daemon, ensure docker is not running or delete /var/run/docker.pid: process with PID 1234 is still running1 more line it can show

Fix it fast

Most common cause, 1 of 2

A Docker daemon is already running, so the second start is refused

Use the daemon that is running, or stop the service before starting dockerd by hand, and start the service again when you are done.

Fix
# keep the service and just use it
docker info

# or run a foreground daemon for debugging
sudo systemctl stop docker
sudo dockerd --debug
# Ctrl+C stops it; then bring the service back
sudo systemctl start docker
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

failed to start daemon, ensure docker is not running or delete /var/run/docker.pid means dockerd found a live process at the PID in its pid file. Either a Docker daemon is already up, usually the systemd service, or the file is stale and another process now has that number. Check the PID before deleting the file. Docker Engine 28 and 29.

  • Applies to Docker Engine 29.10, Docker Engine 28, Ubuntu 24.04 (systemd)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Read the PID from the file and ask what that process is. A dockerd at that PID is cause 1. Any other program, or no dockerd anywhere in the process list, is cause 2.

Run this first
cat /var/run/docker.pid
ps -o pid,comm,args -p "$(cat /var/run/docker.pid)"
pgrep -a dockerd

Then find the line you see in this list and open its fix:

  1. 1A Docker daemon is already running, so the second start is refusedps shows dockerd at the PID from the file, and systemctl reports the docker service as active
  2. 2The pid file is stale and its PID now belongs to another processps shows some other program at that PID (or nothing obvious), and pgrep finds no dockerd at all

What does the error look like?

  • failed to start daemon, ensure docker is not running or delete /var/run/docker.pid: process with PID 1234 is still running
  • failed to start daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid

Cause 1 of 2

A Docker daemon is already running, so the second start is refused

You seeps shows dockerd at the PID from the file, and systemctl reports the docker service as active

Check

Before it writes its own PID, dockerd reads the existing pid file (by default /var/run/docker.pid) and stops with this error when that PID is alive. The usual trigger is typing sudo dockerd to see logs or try a flag while the packaged service is already running; Docker notes that on Ubuntu and Debian the service often starts automatically. Two start mechanisms, such as a service plus a boot script, collide in the same way.

Check
systemctl status docker --no-pager

Fix

Use the daemon that is running, or stop the service before starting dockerd by hand, and start the service again when you are done.

Fix
# keep the service and just use it
docker info

# or run a foreground daemon for debugging
sudo systemctl stop docker
sudo dockerd --debug
# Ctrl+C stops it; then bring the service back
sudo systemctl start docker

Verify

Only one dockerd is in the process list and the client reaches it.

Verify
pgrep -a dockerd
docker info --format '{{.ServerVersion}}'

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 2

The pid file is stale and its PID now belongs to another process

You seeps shows some other program at that PID (or nothing obvious), and pgrep finds no dockerd at all

Check

dockerd removes its pid file on a clean shutdown, through a deferred cleanup in its start routine, so a crash, a kill -9 or a power cut leaves the file behind. On Linux the liveness test only checks whether /proc/<PID> exists, which means any process that later received the same number, even an unrelated one, counts as running. So once the number from a leftover file has been given to a new process, dockerd refuses to start even though no daemon is running.

Check
cat /proc/$(cat /var/run/docker.pid)/comm

Fix

Make sure no dockerd is running, then remove the stale file and start Docker the normal way.

Fix
pgrep -x dockerd || sudo rm /var/run/docker.pid
sudo systemctl start docker

Verify

The service is active, the pid file now holds the PID of the new dockerd, and ps confirms it.

Verify
systemctl is-active docker
ps -o comm= -p "$(cat /var/run/docker.pid)"

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Start Docker through one mechanism only: the systemd service, or a boot script, never both.
  • When you need an extra daemon for testing, give it its own --pidfile, --data-root, --exec-root and --host, which the dockerd reference lists as required for each daemon on one host.
  • Stop the daemon with systemctl stop docker instead of kill -9, so it can remove its pid file on the way out.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.