CentOS7 Docker 安装

时间:2023-03-09 18:45:48
CentOS7 Docker 安装

CentOS7 已经内置了docker ,可以直接安装

安装Docker

  命令: sudo yum install -y docker

  CentOS7 Docker 安装

 启动docker 

  命令: service docker start

  发现会出现异常

  无法启动:
  按照提示执行:
  命令: systemctl status docker.service

    这是由于overlay2不支持造成的,所以我们要关闭它

  命令: vim /etc/sysconfig/docker

  进入修改配置  selinux-enabled=false

  CentOS7 Docker 安装

 

再次执行  service docker start

 执行命令: docker -v  
启动成功。

修改Docker镜像加速器

  国外的docker镜像访问速度太慢 所以我们可以修改成阿里的docker镜像。这样速度会快很多。 

  1.打开阿里云docker仓库地址https://dev.aliyun.com/search.html

  2.淘宝账号即可登录,登录后点击自己的管理中心。

  3.点击管理中心左侧菜单栏的“镜像加速器”,右边面板会有你的加速地址,面板下面有详细设置步骤。如下图:

  CentOS7 Docker 安装

root@localhost ~]# vi /etc/docker/daemon.json

   将下面整行字符拷贝进去,保存并退出

"registry-mirrors": ["https://xrij41fy.mirror.aliyuncs.com"]

  :wq!

刷新daemon

[root@localhost ~]# systemctl daemon-reload

 重启docker

[root@localhost ~]# systemctl restart docker

  

拉取镜像

以hello-world为例

CentOS7 Docker 安装
[root@localhost tmp]# docker pull hello-world
Using default tag: latest
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for docker.io/hello-world:latest
CentOS7 Docker 安装

 表示成功拉取

运行镜像

CentOS7 Docker 安装
[root@localhost tmp]# docker run hello-world