1 支持环境
Docker 支持以下版本的 Ubuntu 操作系统:
Focal 20.04 (LTS)
Bionic 18.04 (LTS)
Xenial 16.04 (LTS)
2 卸载旧的docker
sudo apt-get remove docker \
docker-engine \
docker.io
- 旧版本的
Docker
称为docker
或者docker-engine
; - 因为我的
Ubuntu
是新装的,目前未安装docker
,可以从卸载命令可以看出来:
3 安装Docker
3.1 添加HTTPS 传输的软件包以及 CA 证书
- 因为使用 APT 安装,apt 源使用
HTTPS
以确保软件下载过程中不被篡改:
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
3.2 添加软件源的 GPG 密钥
- 目的是确认所下载软件包的合法性;
# 以后文章建议使用国内源
$ curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 官方源
# $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
-
3.3 添加 Docker 软件源
- 向
sources.list
中添加Docker
软件源:
$ sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
# 官方源
# $ sudo add-apt-repository \
# "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
# $(lsb_release -cs) \
# stable"
3.4 安装Docker
- 使用如下命令:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
3.5 自动安装
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
4 Docker启动和验证是否安装ok
4.1 启动Docker
$ sudo systemctl enable docker
$ sudo systemctl start docker
4.2 docker 用户组建立
- 将需要使用
docker
的用户加入docker
用户组; - 建议用户组:
$ sudo groupadd docker
- 将当前用户加入刚才建议的
docker
组:
$ sudo usermod -aG docker $USER
- 使用:
cat /etc/group
可以查看加入的用户组;
4.3 验证docker
- 退出重新登录,输入命令查看:
$ docker run hello-world
- 输出以下信息表明安装成功了~
noamanelson@noamanelson-Virtual-Machine:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:4e83453afed1b4fa1a3500525091dbfca6ce1e66903fd4c01ff015dbcb1ba33e
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/