docker入门 - 安装
docker tutorial 1
Changelog
data: 2020-05-26
Added
- 增加 Fedora Docker 安装配置
1. Install docker
The following is taken from the docker documentation, archlinux wiki and some other pages.
1.1 Fedora
Install the latest version of Moby Engine.
1
sudo dnf install docker
Cgroups Exception: For Fedora 31 and higher, you need to enable the backward compatibility for Cgroups.
1
sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"
After running the command, you must reboot for the changes to take effect.
Start the
docker.service
.1
sudo systemctl start docker
Verify that Docker is installed correctly.
1
sudo docker info
1.2 Arch Linux
Install the latest version of Docker Engine - Community
1
yay -S docker
Start the
docker.service
1
sudo systemctl start docker
Verify that Docker Engine - Community is installed correctly.
1
sudo docker info
1.3 Ubuntu & Mint
Update the apt package index:
1
sudo apt-get update
Install packages to allow apt to use a repository over HTTPS:
1
2
3
4
5
6sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-commonAdd Docker’s official GPG key:
1
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Use the following command to set up the stable repository.
- Ubuntu:
1
2
3
4sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/ \
$(lsb_release -cs) \
stable"- Mint 19.x (based Ubuntu Bionic, so):
[Note] There is an error in the official documentation.“ In Ubuntu, it seems to be provided by
software-properties-common
package, while Mint replaced it withmintsources
.” from @rbbernardino.Deletting
[arch=amd64]
can fix it. “ I fixed by just removing the [arch=amd64] from the source.” from @mau21mau.1
2
3
4sudo add-apt-repository \
"deb https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/ \
Bionic \
stable"Update the apt package index.
1
sudo apt-get update
Install the latest version of Docker Engine - Community
1
sudo apt-get install docker-ce docker-ce-cli containerd.io
Verify that Docker Engine - Community is installed correctly.
1
sudo docker info
2. Post-installation steps for Linux
2.1 Manage Docker as a non-root user
To create the docker group and add your user:
Create the docker group.
1
sudo groupadd docker
Add your user to the docker group.
1
sudo usermod -aG docker $USER
Log out and log back in so that your group membership is re-evaluated.
If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take effect.
On Linux, you can also run the following command to activate the changes to groups:
1
newgrp docker
Verify that you can run docker commands without sudo.
1
docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
2.2 Configure Docker to start on boot
1 | sudo systemctl enable docker |
2.3 Configure HTTP/HTTPS proxy
- Create a systemd drop-in directory for the docker service:
1 | sudo mkdir -p /etc/systemd/system/docker.service.d |
- Create a file called
/etc/systemd/system/docker.service.d/https-proxy.conf
that adds the HTTPS_PROXY environment variable:
1 | [Service] |
- Flush changes:
1 | sudo systemctl daemon-reload |
- Restart Docker:
1 | sudo systemctl restart docker |
- Verify that the configuration has been loaded:
1 | systemctl show --property=Environment docker |
3. Daemon configuration file
Change or Create a file called
/etc/docker/daemon.json
that sets theregistry-mirrors
1
sudo vim /etc/docker/daemon.json
1
2
3
4
5
6
7{
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com",
"https://registry.docker-cn.com"
]
}Restart Docker.
1
sudo systemctl restart docker.service
Verify that Docker Engine - Community is installed correctly by running the hello-world image.
1
sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
参考1:Docker Documentation
参考2:阮一峰. Docker 入门教程
参考3:https://pastebin.com/7bdKPafy
参考4:Docker Daemon生产环境关键的几个参数