37

I made the mistake of installing Docker via Snap... Once I realised that snap hadn't permissions to run in my working directory (on a different partition), I removed it. Now I can't use docker after I've installed it via apt-get.

Please help.

I've done sudo snap remove docker but when I sudo apt install docker and run via docker, I get bash: /snap/bin/docker: No such file or directory

invisiblegaudi
  • 373
  • 1
  • 3
  • 6

5 Answers5

14

I had the same problem. This works for me.

sudo snap remove docker
sudo reboot 

the point is to restart the instance or terminal.

I hope this method can help

B.P.
  • 141
  • 1
  • 3
  • 11
    `sudo snap remove docker --purge` was very helpful in my case to avoid making a snapshot during removal that was taking a very long time. – jorgeca Feb 15 '23 at 12:45
10

The command you are looking for is:

sudo apt install docker.io

i.e it's docker.io not just docker

On Ubuntu, the package docker is described as a "System tray for KDE3/GNOME2 applications", which is probably not what you want!

slonik
  • 1,144
  • 11
  • 13
  • 1
    Or `sudo apt install docker-ce` – for the difference see [this question](https://stackoverflow.com/q/45023363/4850949) – not2savvy Nov 24 '22 at 23:05
5

I did the same and just restarting the instance fixed it.

Santi Barbat
  • 2,097
  • 2
  • 21
  • 26
  • 5
    Or even just restarting the terminal does it. – Michael Millar Jun 15 '21 at 18:33
  • 2
    @MWMillar Exactly. It is purely an issue with caching of executable locations - a very generic issue in bash not specific to docker, where executables are not in the directory whether they were previously found (although still in PATH). I added an answer with some more detail. – alani Dec 30 '22 at 15:47
3

I had the same issues. The snap installation restricts permissions see https://snapcraft.io/install/docker/ubuntu first bullet point - probably for good security reasons given docker can give unlimited root privileges...).

First, sudo snap remove docker --purge to get rid of it. (from @jorgeca's comment).

Second, following the official installation guide

### remove any previously installed docker remnants
sudo apt-get remove docker docker-engine docker.io containerd runc

### install ca-certificates
sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg

### install docker certs
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

### setup docker repo
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

### install docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

### test installation
sudo docker run hello-world

I also did the following - tests installation binding a volume not in $HOME. This will error out with a snap installation of docker saying the filesystem is read-only.

sudo mkdir /test
sudo docker run -v /test:/test hello-world
sudo rmdir /test
Dave
  • 312
  • 3
  • 11
1

The problem is simply that your bash shell caches the locations of known executables, in order to avoid having to scan through your executables search path (that is, the directories listed in $PATH) every time you type a command. Because you have removed the executable from one directory (/snap/bin) and added it to another directory (/usr/bin), this cache is now out of date. This means that it will look in the wrong location if you try to invoke the executable simply by typing docker rather than its full path.

It is possible to fix it simply by starting a new bash shell, for example open a new terminal window and type the command in there.

Alternatively if you wish to refresh the cache in the terminal session that you are already using, type:

hash -r

It is not necessary to restart your computer (although this would also work).

alani
  • 12,573
  • 2
  • 13
  • 23