Centos7 安装Docker

CentOS7 安装Docker

前情提要:使用任意方式安装好CentOS7 , 确保主机可以接入网络。[ 虚拟机安装建议使用桥接模式 ]

使用 addr ip 查看主机ip
由于CentOS 7 默认是不启动网卡的

vi /etc/sysconfig/network-scripts/ifcfg-ens33

可以看到(ONBOOT=no)
把这一项改为YES(ONBOOT=yes)
然后重启网络服务: sudo service network restart
然后我们再输入 ip addr 命令
为了更方便的查看ip信息 建议安装 ifconfig 命令

yum search ifconfig
-- 通过yum search 这个命令我们发现ifconfig这个命令是在net-tools.x86_64这个包里,接下来我们安装这个包就行了
yum install net-tools.x86_64

Docker 要求 CentOS 系统的内核版本高于 3.10
通过 uname -r 命令查看你当前的内核版本

[root@localhost ~]# uname -r 
3.10.0-862.el7.x86_64

这里我们安装 Docker CE 即社区免费版

如果你安装过旧版本,请卸载旧的版本:

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

安装一些必要的系统工具:

yum install -y yum-utils device-mapper-persistent-data lvm2

添加软件源信息:

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

更新 yum 缓存:

yum makecache fast

安装 Docker-ce:

yum -y install docker-ce

启动 Docker 后台服务

systemctl start docker

查看Docker版本

[root@localhost ~]# docker version

Client: Docker Engine - Community
 Version:           19.03.3
 API version:       1.40
 Go version:        go1.12.10
 Git commit:        a872fc2f86
 Built:             Tue Oct  8 00:58:10 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.3
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.10
  Git commit:       a872fc2f86
  Built:            Tue Oct  8 00:56:46 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

可见我们的 Docker 的 Client 和 Server 已经正常安装了

更改镜像源

vi /etc/docker/daemon.json

写入如下内容[使用网易镜像]

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

重启Docker服务

systemctl daemon-reload 
systemctl restart docker

拉取Hello world 镜像

docker pull hello-world
[root@localhost ~]# docker pull hello-world

Using default tag: latest
latest: Pulling from library/hello-world
Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Image is up to date for hello-world:latest
docker.io/library/hello-world:latest

查看镜像[ 如下 我们已经拉取hello world 到本地了 ]

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        9 months ago        1.84kB

下面运行hello world [ 如下已经顺利的运行的hello world ]

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

如要您想要删除docker ce

$ sudo yum remove docker-ce
$ sudo rm -rf /var/lib/docker

? see you

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值