31

I added the docker snap package to my Ubuntu 16.04 machine

sudo snap install docker

Now, when I try to use it, I get the following error...

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

1
  • 1
    I didn't find any of thes solutions terribly helpful and ended up resort to installing via apt instead. Sep 1, 2022 at 23:53

4 Answers 4

25

Due to confinement issues in the evolving snappy model, Docker is not full flavored by default (see the discussion on the Snapcraft forum).

To get some helpful instructions on how to work around (i.e. break) the confinement model until the proper fix is in place. You can simply check the Docker help application packaged in the snap.

$ docker.help
Docker snap: Docker Linux container runtime.

Due to the confinement issues on snappy, it requires some manual setup to make docker-snap works on your machine.
We'll take you through the steps needed to set up docker snap work for you on ubuntu core and ubuntu classic.

On Ubuntu classic, before installing the docker snap, 
please run the following command to add the login user into docker group.
    sudo addgroup --system docker
    sudo adduser $USER docker
    newgrp docker

On Ubuntu Core 16, after installing the docker snap from store,
Firstly, you need to connect the two interfaces as they're not auto-connected by default.
    sudo snap connect docker:account-control :account-control
    sudo snap connect docker:home :home

Secondly, reload the snap and allows the user to login to the new group "docker-snap".
    snap disable docker
    snap enable  docker
    newgrp docker-snap

Then have fun with docker in snappy.

The last command fails...

$ newgrp docker-snap
newgrp: group 'docker-snap' does not exist

However, I did not notice any negative impact based on the failure, and Docker now functions as I would expect.

2
  • Aligning with the above, you can read the instructions for using the Ubuntu snap version of docker as a regular user over on snapcraft (see the commands beneath the "Running Docker as normal user" heading).
    – Anon
    Jun 13, 2021 at 14:59
  • Note: docker.help does not provide the same set of instructions as above, however 'sudo snap enable|disable docker' commands from above were the missing steps I needed.
    – Digicrat
    Nov 9, 2021 at 22:49
12

Use snap start docker to activate the service. It might need root permissions.

2
  • didn't help: Cannot connect to the Docker daemon
    – maslick
    Nov 19, 2019 at 9:27
  • 1
    @maslick sudo snap start docker Oct 13, 2022 at 15:21
6

If ...

sudo snap start docker

... does not help, try to remove and reinstall docker

sudo snap remove docker --purge

this also will delete images, containers and stuff docker has created

sudo snap install docker
2
  • Bravo!! All above solutions failed, and only this one works for me, when I want to run docker images without sudo! thanks!
    – xpt
    Feb 9, 2022 at 22:21
  • 1
    this also will delete images, containers and stuff docker has created. What about volumes?
    – birgersp
    Aug 29, 2022 at 11:26
2

I got this working by running:

sudo snap start docker

then running sudo on subsequent docker commands:

sudo docker-compose up --build

Without the sudo on the subsequent docker commands, the Cannot connect to the Docker daemon error persists.

2
  • 1
    Unless there's another issue here, if you create a group called docker and add your account to it, docker will use that group for its socket so you can use it without sudo. groupadd docker && usermod -a -G docker username && reboot. Jul 10, 2020 at 11:21
  • I dunno, seems like a good idea to use sudo -- or at least a special user. Aug 17, 2021 at 0:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .