您现在的位置是:首页 > 文章详情

Docker在linux系统下的安装

日期:2019-05-05点击:320

系统要求

本安装教程仅限于CentOS7,其他系统不适用。
centos-extras仓库必须是启用状态,这个仓库默认状态是启用,如果不是启用状态,请修改。

卸载旧版本的Docker

Docker的旧版本叫做docker或者docker-engine。现在的Docker版本是Docker CE(社区版)和Docker EE(企业版)。一般情况下,咱们使用Docker CE(社区版)就可以了。如果你的系统安装了旧版本,卸载它们以及与它们相关的依赖。命令如下:

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

如果你的系统中没有安装旧版本的Docker,将会出现如下提示:

已加载插件:fastestmirror 参数 docker 没有匹配 参数 docker-client 没有匹配 参数 docker-client-latest 没有匹配 参数 docker-common 没有匹配 参数 docker-latest 没有匹配 参数 docker-latest-logrotate 没有匹配 参数 docker-logrotate 没有匹配 参数 docker-engine 没有匹配 不删除任何软件包

安装Docker

如果你是在主机上第一次安装Docker CE,需要设置Docker的仓库。以后就可以从这个仓库安装和更新Docker了。

设置仓库

  • 安装所需的包,yum-utils提供yum-config-manager工具,device-mapper-persistent-datalvm2devicemapper存储驱动所需要的。安装命令如下:
$ 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 CE

  • 安装最新版本的Docker CE
$ sudo yum install docker-ce docker-ce-cli containerd.io

命令完成后,Docker已经安装,但是并没有启动。

  • 启动Docker
$ sudo systemctl start docker
  • 通过运行hello-world镜像验证Docker CE是否安装成功。
$ sudo docker run hello-world

运行结果如下:

Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e Status: Downloaded newer image for hello-world:latest 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的卸载

  • 卸载Docker包
$ sudo yum remove docker-ce
  • 镜像、容器、自定义配置文件等并不会随着Docker的卸载自动删除,你需要执行一下命令手动删除:
$ sudo rm -rf /var/lib/docker

到这里,Docker的安装与卸载过程就给大家介绍完了。

原文链接:https://yq.aliyun.com/articles/701340
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章