Skip to content

Instantly share code, notes, and snippets.

@1eedaegon
Last active April 26, 2024 05:36
Show Gist options
  • Save 1eedaegon/fa1c03c1044782aea8a9f042fece801e to your computer and use it in GitHub Desktop.
Save 1eedaegon/fa1c03c1044782aea8a9f042fece801e to your computer and use it in GitHub Desktop.
When start failed docker on wsl2 ubuntu

Inspect log

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? See journal

journalctl -xeu docker

Nov 15 14:42:36 1eegram systemd[1]: Starting Docker Application Container Engine...
░░ Subject: A start job for unit docker.service has begun execution
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit docker.service has begun execution.
░░
░░ The job identifier is 1511.
Nov 15 14:42:36 1eegram dockerd[2364]: time="2023-11-15T14:42:36.469366577+09:00" level=info msg="Starting up"
Nov 15 14:42:37 1eegram dockerd[2364]: failed to start daemon: error while opening volume store metadata database (/var/lib/docker/volumes/metadata.db): ti>
Nov 15 14:42:37 1eegram systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ An ExecStart= process belonging to unit docker.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Nov 15 14:42:37 1eegram systemd[1]: docker.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ The unit docker.service has entered the 'failed' state with result 'exit-code'.
Nov 15 14:42:37 1eegram systemd[1]: Failed to start Docker Application Container Engine.
░░ Subject: A start job for unit docker.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit docker.service has finished with a failure.
░░
░░ The job identifier is 1511 and the job result is failed.
Nov 15 14:42:47 1eegram systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.

If you are using wsl2 and installed without using docker desktop, the problem is most likely below.

  • Duplicated pid
  • Already mounted /var/lib/docker
  • Too fast restart dockerd

Manually execute

so, execute script this:

  1. ps axf | grep docker | grep -v grep | awk '{print "kill -9 " $1}' | sudo sh
  2. All stop docker
    • sudo systemctl stop '*docker*'
  3. Daemon reloading
    • sudo systemctl daemon-reload
  4. Restart and start pre-start scripts
    • sudo systemctl start docker
  5. See status
    • sudo systemctl status '*docker*'
ps axf | grep docker | grep -v grep | awk '{print "kill -9 " $1}' | sudo sh
sudo systemctl stop '*docker*'
sudo systemctl daemon-reload
sudo systemctl start docker

Fix docker.service

Add some lines like below:

[Service]
...
ExecStartPre=/bin/rm -f /var/run/docker.pid 
ExecStartPre=/bin/sh -c 'ps axf | grep docker | grep -v grep | awk \'{print "kill -9 " $1}\' | sh'
# ps axf | grep docker | grep -v grep | awk '{print "kill -9 " $1}' | sudo sh
...
TimeoutStartSec=10
RestartSec=10
Restart=always
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment