centos7下Docker安装

由于很多项目都需要在特定的环境下才能稳定运行,在网上搜索一番后,觉得Doceker是一个很不错的容器化平台,决定学习踩坑,先把Docker安装上吧.
Docker有两个版本,社区版(CE),企业版(EE),这里的是社区版。服务器系统是阿里云centos7.4。
旧版本的Docker
下列代码可以卸载旧版本的Docker和相关的依赖项。

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

由于之前没安装过Docker,这步跳过。
安装Docker CE
使用推荐方法设置Docker的存储库并从中进行安装。
设置存储库
安装所需的包。yum-utils提供了yum-config-manager 效用,并device-mapper-persistent-data和lvm2由需要 devicemapper存储驱动程序。

$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

使用以下命令设置稳定存储库。即使您还想从边缘或测试存储库安装构建,您始终需要稳定的存储库。

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

可选:启用边缘和测试存储库。这些存储库包含在docker.repo上面的文件中,但默认情况下处于禁用状态。您可以将它们与稳定存储库一起启用。

$ sudo yum-config-manager --enable docker-ce-edge
$ sudo yum-config-manager --enable docker-ce-test

执行以上命令。

安装Docker CE
执行命令安装最新版本的Docker CE:

sudo yum install docker-ce

启动Docker:

$ sudo systemctl start docker

docker通过运行hello-world 映像验证是否已正确安装:

$ sudo docker run hello-world

到这一步,会出现下列信息:

[root@iZwz98z8juypkza3zpl0c6Z myProject]# 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/engine/userguide/

至此docker ce 安装成功

    原文作者:daoist
    原文地址: https://segmentfault.com/a/1190000015876739
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞