CentOS-CentOS8 install Docker

Official reference address: https://docs.docker.com/install/linux/docker-ce/centos/

It contains the package download address:  https://download.docker.com/linux/centos/7/x86_64/stable/Packages/ 

Install dependencies

sudo yum install -y yum-utils  device-mapper-persistent-data  lvm2
sudo yum-config-manager  --add-repo   https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io

If an error is reported: Problem: package docker-ce-3: 19.03.4-3.el7.x86_64 requires containerd.io> = 1.2.2-3 Then install the new version of containerd.io first

dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

Install the remaining two

sudo yum install docker-ce docker-ce-cli
sudo systemctl start docker
docker --version

Power on

sudo systemctl enable docker

 

If the foreign Docker image is slow, you can install Docker based on the Alibaba Cloud image.

Execute the following three commands to download Docker from the Alibaba Cloud image. Note that the link to the second command given below is the latest link at the time of writing the article. It is best to check for updates when actually downloading.

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
dnf install https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.1.el7.x86_64.rpm
dnf install docker-ce

Next, set Docker to start and start Docker:

systemctl enable docker.service
systemctl start docker.service

Then, you can use Docker.

Next, we can use Docker to create containers:

docker info                # 查看docker的信息
docker search img_name     # 搜索名为img_name的镜像
docker pull img_name       # 将名为img_name的镜像下载到本地
docker images              # 查看本地已有的镜像
docker rmi img_name        # 删除名为img_name的镜像

docker ps                  # 列出正在运行的容器
docker ps -a               # 列出所有的容器
docker run -itd --name=container_name img_name  # 使用img_name以交互模式在后台运行分配了伪终端的名为container_name的镜像

docker start container_name/container_id        # 通过容器名字或ID启动容器
docker stop container_name/container_id         # 通过容器名字或ID停止容器
docker restart container_name/container_id      # 通过容器名字或ID重启容器
docker rm container_name/container_id           # 通过容器名字或ID删除容器

docker exec -it container_name/container_id /bin/bash   # 通过容器名字或ID进入容器
exit               # 退出容器

 

1353 original articles have been published · 2379 praises · 5.43 million views

Guess you like

Origin blog.csdn.net/l1028386804/article/details/105480007