Skip to content

Instantly share code, notes, and snippets.

@mdanshin
Last active November 17, 2021 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdanshin/49c2cfdc99e8104db36ae0b68811c26e to your computer and use it in GitHub Desktop.
Save mdanshin/49c2cfdc99e8104db36ae0b68811c26e to your computer and use it in GitHub Desktop.
Autostart docker on wsl2

Create line in sudo visudo (at WSL to prevent asking password):

  %sudo   ALL=(ALL) NOPASSWD: /usr/sbin/service docker start

Add in ~/.bashrc

# Start Docker daemon automatically when logging in if not running.
RUNNING=`ps aux | grep dockerd | grep -v grep`
if [ -z "$RUNNING" ]; then
    sudo /usr/sbin/service docker start > /dev/null 2>&1 &
    disown
fi

After restarting the service, it will start automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment