前提
使用的 Ubuntu版本是 Ubuntu 18.04
使用 sudo lsb_release -a
查看 Ubuntu 版本
$ sudo lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
提示:千萬不要在沒有配置 Docker APT 源的情況下直接使用 apt
命令安裝 Docker
配置 APT 源
首先需要添加 HTTPS 軟件包和 CA 證書
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
添加軟件源的 GPG 密鑰
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
查看密鑰是否安裝成功
$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]
添加軟件源 /etc/apt/sources.list
sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# deepin 使用下面的
sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian jessie stable"
安裝 Docker CE
更新 apt 軟甲包緩存
sudo apt-get update
安裝 Docker
sudo apt-get install docker-ce
manjaro 安裝
Manjaro 可直接使用下面命令直接安裝
sudo pacman -S docker
設置開機自啟
sudo systemctl enable docker
啟動 Docker
sudo systemctl start docker
使用 docker run hello-world
驗證 Docker 是否安裝成功
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Already exists
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
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/
至此安裝完成。
建立 Docker 用戶組(可省略)
默認情況下,docker
命令會使用 Unix Socket 與 Docker 引擎通信,只有 root 用戶和 docker 用戶組才能使用,而一般生產環境不會直接使用 root 用戶,因此我們需要將需要使用 docker 的用戶加入 docker 用戶組。
將當前用戶加入 docker 用戶組
sudo usermod -aG docker 用戶名
鏡像加速(可省略)
國內從 Docker Hub 拉取鏡像很慢,可以通過配置鏡像加速器解決這一問題,下面使用的是 Docker 官方提供的鏡像加速服務。
配置 Docker 鏡像加速
cat /etc/docker/daemon.josn
{
“registry-mirrors”: [
"https://registry.docker-cn.com"
]
}
重啟服務,使配置生效
sudo systemctl daemon-reload
sudo systemctl restart docker
關于 Deppin
安裝按照上面方式安裝 Docker 會失敗,正確的安裝姿勢可以看這篇文章:Docker - deepin Wiki