22

The Docker command is not working after restarting (using sudo reboot) the Ubuntu (20.04) server.

Now, for any command with docker, it gives me an error. For example,

$ docker --help
cannot update snap namespace: cannot create symlink in "/etc/docker": existing file in the way
snap-update-ns failed with code 1

When I manually check, there is a file called key.json in the /etc/docker folder which has a json dictionary.

Before restarting, I have had few docker containers running in the background with volume connected. When I run systemctl start docker as mentioned in one StackOverflow answer, I am getting

Failed to start docker.service: Unit docker.service not found.

It would be great at least to recover the docker images that were there before restarting.

-- Edit --

For some reason, docker is working now. I have restarted once again after the initial restart which resulted in the error. But there was no improvement. However, it is working fine now. I do not know what solved the issue, maybe the cmd journalctl -u docker.service (as suggested in a comment) help in some way, or some other reason.

So, It would be great if someone can answer what was the initial reason for the trouble? It might help us to avoid this in the future.

Wenuka
  • 887
  • 2
  • 9
  • 25
  • Can you provide the logs from the docker service? (With something like: `journalctl -u docker.service`) – Aaron N. Brock Sep 10 '21 at 19:41
  • @AaronN.Brock It says `-- No entries --` and the log starts from the time that I did the restart (I guess because it's two days ago). – Wenuka Sep 12 '21 at 19:53
  • For some reason, docker is working now. I have restarted once again after the initial restart which resulted in the error. But there was no improvement. However, it is working fine now. I do not know what solved the issue, maybe the cmd `journalctl -u docker.service` help in some way, or some other reason. It would be great if someone know what was the initial reason for the trouble. – Wenuka Sep 12 '21 at 20:15

1 Answers1

57

It looks like a Snap-related Issue. I Found a fix on the SnapCraft forum here :

https://forum.snapcraft.io/t/layouts-still-brittle-when-refreshing-snaps/26252/5

  sudo rm -rf /etc/docker
  sudo snap refresh

Works in both Ubuntu 18.04.5 and 20.04.5 LTS.

Webfab
  • 670
  • 3
  • 4
  • 1
    I had docker installed probably with apt. Needed to install docker-compose but could not using apt (Forbidden errors on sources.list), tried to use snap to install docker and had this error. Removing `/etc/docker` allowed to install docker from snap with docker-compose. Ubuntu 20.04. – Vladislav Povorozniuc Oct 22 '21 at 16:00