Score:0

Cannot run docker after install by snap command inside Ubuntu 22.04 EC2

in flag

In the past, I can run docker easily by command sudo apt-get install docker... . Today, I tried experience new way, install by snap command, then

enter image description here

Microsoft Windows [Version 10.0.19044.2486]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Administrator\Downloads>ssh -i "vy.pem" [email protected]
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-1028-aws x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Jan 30 02:00:14 UTC 2023

  System load:  0.16845703125     Processes:                111
  Usage of /:   21.7% of 7.57GB   Users logged in:          0
  Memory usage: 3%                IPv4 address for docker0: 172.17.0.1
  Swap usage:   0%                IPv4 address for eth0:    172.31.32.168


0 updates can be applied immediately.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Mon Jan 30 02:00:15 2023 from 14.248.82.245
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-1028-aws x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Jan 30 02:00:14 UTC 2023

  System load:  0.16845703125     Processes:                111
  Usage of /:   21.7% of 7.57GB   Users logged in:          0
  Memory usage: 3%                IPv4 address for docker0: 172.17.0.1
  Swap usage:   0%                IPv4 address for eth0:    172.31.32.168


0 updates can be applied immediately.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Mon Jan 30 02:00:15 2023 from 14.248.82.245
ubuntu@ip-172-31-32-168:~$ docker ps -a
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1": dial unix /var/run/docker.sock: connect: permission denied
ubuntu@ip-172-31-32-168:~$ sudo usermod -aG docker $USER
ubuntu@ip-172-31-32-168:~$ newgrp docker
ubuntu@ip-172-31-32-168:~$ docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
ubuntu@ip-172-31-32-168:~$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
chmod g+rwx "$HOME/.docker" -Rsudo chmod g+rwx "$HOME/.docker" -Rchown: cannot access '/home/ubuntu/.docker': No such file or directory
ubuntu@ip-172-31-32-168:~$ sudo groupadd docker
groupadd: group 'docker' already exists
ubuntu@ip-172-31-32-168:~$ sudo usermod -aG docker ${USER}
ubuntu@ip-172-31-32-168:~$ su -s ${USER}
Password:
^C
ubuntu@ip-172-31-32-168:~$ exit
exit
ubuntu@ip-172-31-32-168:~$ exit
logout
Connection to ec2-18-142-158-158.ap-southeast-1.compute.amazonaws.com closed.

C:\Users\Administrator\Downloads>ssh -i "vy.pem" [email protected]
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-1028-aws x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Jan 30 02:03:18 UTC 2023

  System load:  0.01220703125     Processes:                113
  Usage of /:   21.7% of 7.57GB   Users logged in:          0
  Memory usage: 3%                IPv4 address for docker0: 172.17.0.1
  Swap usage:   0%                IPv4 address for eth0:    172.31.32.168


0 updates can be applied immediately.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Mon Jan 30 02:00:57 2023 from 14.248.82.245
ubuntu@ip-172-31-32-168:~$ docker ps -a
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1": dial unix /var/run/docker.sock: connect: permission denied
ubuntu@ip-172-31-32-168:~$ usermod -aG docker ${USER}
usermod: Permission denied.
usermod: cannot lock /etc/passwd; try again later.
ubuntu@ip-172-31-32-168:~$ docker ps -a
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1": dial unix /var/run/docker.sock: connect: permission denied
ubuntu@ip-172-31-32-168:~$ sudo service docker restart
Failed to restart docker.service: Unit docker.service not found.
ubuntu@ip-172-31-32-168:~$
ubuntu@ip-172-31-32-168:~$
ubuntu@ip-172-31-32-168:~$
ubuntu@ip-172-31-32-168:~$
ubuntu@ip-172-31-32-168:~$
ubuntu@ip-172-31-32-168:~$ docker ps -a
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1": dial unix /var/run/docker.sock: connect: permission denied
ubuntu@ip-172-31-32-168:~$ su root
Password:
root@ip-172-31-32-168:/home/ubuntu#
root@ip-172-31-32-168:/home/ubuntu#
root@ip-172-31-32-168:/home/ubuntu#
root@ip-172-31-32-168:/home/ubuntu# docker build . -t kong-your-tag
error checking context: 'no permission to read from '/home/ubuntu/.bash_history''.
root@ip-172-31-32-168:/home/ubuntu#

How to use docker as normal?

dummyuser avatar
uy flag
please edit your question an add the result of grep `docker /etc/group`
Score:4
pl flag

The snapcraft store page for docker explains what to do. https://snapcraft.io/docker

A snippet:

"By default, Docker is only accessible with root privileges (sudo). If you want to use docker as a regular user, you need to add your user to the docker group."

 sudo addgroup --system docker
 sudo adduser $USER docker
 newgrp docker
 sudo snap disable docker
 sudo snap enable docker
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.