CentOS7下安装Docker

2021-05-18  本文已影响0人  程序员小华

Docker目前主要分为两个版本:Docker EE(企业版)和Docker CE(社区版)。本文主要介绍Docker CE的安装

1. 准备条件

通过 uname -r 查看CentOS的内核是否在3.10以上,CentOS7下安装docker必须要求系统内核高于3.10

[root@localhost ~]# uname -r
3.10.0-957.el7.x86_64
2. 通过下面命令将之前安装过的docker组件移除
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
3. 通过下面命令安装docker所需要的依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
4. 添加软件源信息
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
5. 更新yum缓存
yum makecache fast
6. 安装docker-ce
yum -y install docker-ce
7. 添加镜像加速

由于docker镜像拉取需要访问国外网站,所以在国内拉取docker镜像比较慢,这里通过配置镜像地址来解决,这里配置的是网易镜像地址:http://hub-mirror.c.163.com
/etc/docker/daemon.json文件(文件若不存在则新建)添加以下代码:

{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}

保存后退出

8. 启动docker
systemctl start docker

测试docker是否安装成功,运行一个测试的镜像hello-world

[root@localhost docker]# 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/

[root@localhost docker]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@localhost docker]# 

由上面的信息可以看到,docker容器运行成功

9. 关闭docker
systemctl stop docker;
上一篇下一篇

猜你喜欢

热点阅读