以前我可以通过命令很方便的运行docker sudo apt-get install docker...
,今天我尝试了一下新方法,通过snap命令安装,然后
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#
如何正常使用docker?
答案1
docker 的 snapcraft 商店页面解释了该如何做。https://snapcraft.io/docker
片段如下:
“默认情况下,只有具有 root 权限 (sudo) 才能访问 Docker。如果您想以普通用户身份使用 docker,则需要将您的用户添加到 docker 组。”
sudo addgroup --system docker
sudo adduser $USER docker
newgrp docker
sudo snap disable docker
sudo snap enable docker