centos7 安装启动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/

猜你喜欢

转载自blog.csdn.net/wejack/article/details/130932795