centos7 安装启动docker

文章详细介绍了如何在CentOS7环境下卸载旧版Docker,设置Docker源,安装最新版本,并解决安装过程中可能出现的问题,最后通过运行hello-world验证Docker是否正确安装。

直接到docker的官网找centos安装docker的文档。文档地址:https://docs.docker.com/engine/install/centos/

安装环境 CentOS 7

卸载旧版本

如果没装过可以省略这一步

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

卸载时/var/lib/docker/目录下存储的镜像、容器、磁盘、网络等不会自动移除。

安装准备

在新机器安装docker引擎时,需要先设置docker源,然后可以从docker源中安装和更新docker。

# 安装yum工具包
$ sudo yum install -y yum-utils
# 设置源
$ 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 docker-buildx-plugin docker-compose-plugin
  • 如果在安装过程中出现以下问题,可以将docker repo配置文件/etc/yum.repos.d/CentOS-Base.repo里的gpgcheck属性的值改成0.

    …………
    Is this ok [y/d/N]: y
    Downloading packages:
    警告:/var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-24.0.2-1.el7.x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 621e9f35: NOKEY
    从 https://download.docker.com/linux/centos/gpg 检索密钥
    
    
    获取 GPG 密钥失败:[Errno 12] Timeout on https://download.docker.com/linux/centos/gpg: (28, 'Operation timed out after 30000 milliseconds with 0 out of 0 bytes received')
    
启动docker
systemctl start docker
验证docker
$ docker run hello-world
[root@docker_121 ~]# docker run hello-world

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/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值