0. 机器环境
ubuntu 16.04
CE(社区版)docker
1. 设置docker仓库
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
# 添加 docker 官方 GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
# 确认输出有 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
# 设置仓库
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
2. 安装docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
# 列出可以安装的版本
apt-cache madison docker-ce
# 安装指定版本
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
# 例如这里选择版本 5:18.09.1~3-0~ubuntu-xenial
# 验证是否安装成功
sudo docker run hello-world
显示如下则表示安装成功:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
3. 遇到的问题
3.1 ModuleNotFoundError: No module named 'apt_pkg'
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
解决办法:
sudo apt-get remove --purge python-apt
sudo apt-get install python-apt -f
cd /usr/lib/python3/dist-packages/
sudo cp apt_pkg.cpython-3?m-x86_64-linux-gnu.so apt_pkg.cpython-36m-x86_64-linux-gnu.so
3.2 每次输入都需要输入 sudo
-
如果还没有 docker group 就添加一个:
sudo groupadd docker
-
将用户加入该 group 内。然后退出并重新登录就生效啦。
sudo gpasswd -a ${USER} docker
-
重启 docker 服务
sudo service docker restart
-
切换当前会话到新 group 或者重启
newgrp - docker