How to remove a snap application (docker) completely

74.8k Views Asked by At

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

5

There are 5 best solutions below

2
Santi Barbat On

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

1
slonik On

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!

1
B.P. On

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

0
alani On

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).

0
Dave On

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