Having worked with CentOS for many years, content may not apply to macOS or Ubuntu users in some cases.
You can refer to the documentation from Tsinghua University for installation guidance: https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/
Installation
Due to unknown mysterious forces, domestic Docker installation is recommended to set the cloud vendor’s repository address. Here we recommend using Alibaba Cloud.
Set Repository Source Address
yum install yum-utils device-mapper-persistent-data lvm2 && \
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Deploy the Latest Version
Docker is a commonly used background service, we recommend setting it to start on boot. The following command applies to CentOS 7:
sudo yum install -y docker-ce docker-ce-cli containerd.io && systemctl enable --now docker
Deploying a Specific Version
The releases of kubernetes
and docker
are not fully synchronized. If you need to deploy kubernetes
subsequently, refer to the kubernetes
deployment instructions and install a specific version of docker
.
yum list docker-ce --showduplicates | sort -r
sudo yum install -y docker-ce-18.09.2-3.el7 docker-ce-cli-18.09.2-3.el7 containerd.io-18.09.2-3.el7 && systemctl enable --now docker
Adding Docker Permissions for Regular Users
sudo usermod -aG docker ${USER}
Uninstall
sudo yum erase -y docker-ce docker-ce-cli containerd.io
Everyday Use
Mirror Acceleration
There’s still an unknown mysterious force that causes slow image pulls. At this time, domestic cloud vendors have emerged and provided many acceleration services, which are still recommended – Alibaba Cloud.
The acceleration addresses can be managed by you registering an Alibaba Cloud account; this service is free. Alibaba Cloud also offers a free image build service.
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://docker.nju.edu.cn",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.mirrors.sjtug.sjtu.edu.cn"
]
}
EOF
systemctl daemon-reload && \
systemctl restart docker
Recommended Control Panels
docker volume create portainer_data && \
docker run -d --name=portainer --restart=always -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:2.20.3-alpine
Frequently Used Image Pull List
docker pull rancher/rancher:stable && docker pull portainer/portainer-ce:2.0.1 && \
docker pull centos:7 && docker pull ubuntu:20.04 && docker pull ubuntu:18.04 && \
docker pull redis:5 && docker pull redis:6 && \
docker pull alpine:3.11 && docker pull busybox:1.32 && \
docker pull rabbitmq:3.7-management && \
docker pull mariadb:10.2 && \
docker pull nginx:1.18 && docker pull nginx:1.19 && \
docker pull mysql:5.6 && docker pull mysql:8 && \
docker pull elasticsearch:6.8.11 && docker pull logstash:6.8.11 && docker pull kibana:6.8.11 && \
docker pull zookeeper:3.4 && \
docker pull influxdb:1.7 && docker pull grafana/grafana:7.3.1 && \
docker pull percona:8 && docker pull percona:5.6 && \
docker pull cloverzrg/frps-docker:0.34.3 && docker pull cloverzrg/frpc-docker:0.34.3
Common Command Combinations
https://docs.docker.com/engine/reference/commandline/docker/
View container running status, append the format
parameter to view detailed container information, and ignore image information.
docker ps --format "{{.Names}}: {{.Ports}}: {{.Size}}"
#portainer: 0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp: 0B (virtual 172MB)
#influxdb: 0.0.0.0:8086->8086/tcp: 183B (virtual 311MB)
Stop all containers with one command
docker stop $(docker ps -a -q)
Delete all images with one command
docker rmi $(docker images -a -q)
Export image
docker save <IMAGE NAME>:<IMAGE TAG> > XXX.tar
Export image and compress it
docker save <IMAGE NAME>:<IMAGE TAG> | gzip > XXX.tar
Import image
docker load -i XXX.tar