Centos 7 安装 Docker

官方文档:https://docs.docker.com/engine/install/centos/

卸载旧版本Docker以及关联的依赖项

yum remove docker \
                docker-client \
                docker-client-latest \
                docker-common \
                docker-latest \
                docker-latest-logrotate \
                docker-logrotate \
                docker-engine

安装Docker

#更新 CentOS 系统中的软件包和安装的软件(不是必要的)

yum update -y

#安装 yum-utils 软件包(提供 yum-config-manager 实用程序)并设置存储库

yum install -y yum-utils

# 国外机(二选一):
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 国内机(二选一):
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 快速生成 Yum 软件包管理器的缓存
yum makecache fast

#安装最新版本

yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

#启动Docker

#设置自启动并查看状态
systemctl enable docker
systemctl restart docker
systemctl status docker
#查看docker版本
docker version

#添加阿里云镜像加速地址(国内机)

建议使用自己的加速地址,获取方式:容器镜像服务 (aliyun.com)

#可能是多余的
sudo mkdir -p /etc/docker
cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
#或者使用这个
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF
systemctl daemon-reload
systemctl restart docker  
systemctl status docker 
#检查镜像注册表的配置信息
docker info | grep "Registry Mirrors" -A 1

#测试Docker

docker run hello-world
# 输出如下结果则安装无误
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
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

systemctl stop docker
yum remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker
rm -rf /var/lib/containerd
感谢观看Centos 7 安装 Docker,欢迎分享https://cn-lcx.cn/2023/07/25/centos-7-%e5%ae%89%e8%a3%85-docker/

评论

本文评论已关闭
上一篇
下一篇