当前位置:   article > 正文

Centos8安装Docker

centos8安装docker

官网

官网:https://www.docker.com
文档地址:https://docs.docker.com 超级详细的docker文档
仓库地址:https://hub.docker.com push pull 镜像发布

1、环境准备

  1. # 查看系统内核和操作系统版本
  2. [root@root]# uname -r
  3. 4.18.0-193.el8.x86_64
  4. [root@root]# cat /etc/redhat-release
  5. CentOS Linux release 8.2.2004 (Core)

2、安装

2.1、卸载就版本docker

  1. [root@root]# yum remove docker \
  2. docker-client \
  3. docker-client-latest \
  4. docker-common \
  5. docker-latest \
  6. docker-latest-logrotate \
  7. docker-logrotate \
  8. docker-engine

2.2、安装仓库

[root@root]# sudo yum install -y yum-utils

2.3、设置源地址

  1. [root@root]# sudo yum-config-manager \
  2. https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

配置CentOS8的yum源,参考:CentOS8 配置阿里云的yum源 - 简书

2.4、安装Docker Engine-Community

[root@root]# sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

查看官方帮助文档:https://docs.docker.com/engine/install/centos/

2.4.1、这里安装会报错

conflicting requests - nothing provides container-selinux >= 2:2.74 needed by containerd

原因:container-selinux没有安装或者版本太低

解决方案:下载对应的 rpm 包,并且安装

  1. [root@root]# wget https://vault.centos.org/centos/8/AppStream/x86_64/os/Packages/container-selinux-2.124.0-1.gitf958d0c.module_el8.3.0+569+1bada2e4.noarch.rpm
  2. [root@root]# rpm -ivh container-selinux-2.124.0-1.gitf958d0c.module_el8.3.0+569+1bada2e4.noarch.rpm

版本下载地址 https://pkgs.org/download/container-selinux

2.4.2、安装 rpm 完成之后,重复步骤 2.4

2.5、确认是否安装成功

  1. [root@root]# docker --version
  2. Docker version 20.10.17, build 100c701

2.6、启动运行

[root@root]# systemctl status docker

2.7、运行 helloworld

  1. [root@root]# docker run hello-world
  2. #本地没有找到hello-world的镜像
  3. Unable to find image 'hello-world:latest' locally
  4. # 去下载最新的hello-world镜像
  5. latest: Pulling from library/hello-world
  6. #下载成功
  7. 2db29710123e: Pull complete
  8. Digest: sha256:13e367d31ae85359f42d637adf6da428f76d75dc9afeb3c21faea0d976f5c651
  9. Status: Downloaded newer image for hello-world:latest
  10. #看见这句,说明docker已安装成功
  11. Hello from Docker!
  12. This message shows that your installation appears to be working correctly.

2.7.1、这里会出现一个错

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

原因:docker宕机

2.7.1.1、使用命令查看
  1. [root@root]# systemctl status docker
  2. ● docker.service - Docker Application Container Engine
  3. Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
  4. Active: inactive (dead)
  5. Docs: https://docs.docker.com
2.7.1.2、设置开机启动
[root@root]# systemctl enable docker
2.7.1.3、重启
[root@root]# systemctl restart docker
2.7.1.4、查看状态
  1. [root@root]# systemctl status docker
  2. ● docker.service - Docker Application Container Engine
  3. Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
  4. Active: active (running) since Fri 2024-05-31 14:10:28 CST; 7s ago
  5. Docs: https://docs.docker.com
  6. Main PID: 912446 (dockerd)
  7. Tasks: 8
  8. Memory: 30.2M
  9. CGroup: /system.slice/docker.service
  10. └─912446 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
2.7.1.5、重复步骤 2.7

2.8、查看镜像

  1. [root@root]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. hello-world latest feb5d9fea6a5 9 months ago 13.3kB
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/970559
推荐阅读
相关标签
  

闽ICP备14008679号