工欲善其事,必先利其器。Docker作为分布式微服务部署的绝佳工具当然值得我们学习一下了。
Docker的简介咱们就不谈了,这种资料市面上也很多。本文主要分享一下Docker的在CentOS环境下的安装步骤,以供大家快速准确安全的安装Docker。
一开始本着程序员偷懒的精神我想直接通过“yum install docker-ce”进行,然后命令行窗口报了一个信息“没有可用软件包docker-ce”。没办法,我只好自己找安装文档了。本着要找信息就去信息源头找的原则,我百度了Docker的官网,找到了他们的安装文档。
大家可以打开这个地址https://docs.docker.com/install/linux/docker-ce/centos/,发现安装步骤还是挺多的,说明这不是一件偷懒就能完成的事。
官方推荐使用仓库安装的方法,因为这可以在线更新。
使用存储库安装
设置存储库
安装所需的包。其中
yum-utils
保证yum-config-manager
可用,并且使用device-mapper-persistent-data
和lvm2
作为存储驱动,为Docker提供存储能力。$ 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和containerd,或者转到下一步安装特定版本:
$ sudo yum install docker-ce docker-ce-cli containerd.io
要安装特定版本的Docker CE,请在repo中列出可用版本,然后选择并安装:
$ yum list docker-ce --showduplicates | sort -r
启动Docker。
$ sudo systemctl start docker
通过运行
hello-world
映像验证是否正确安装了Docker CE 。$ sudo docker run hello-world
此命令下载测试映像并在容器中运行它。当容器运行时,它会打印一条信息性消息并退出。
在运行这一条命令的时候,发现命令行打印了这些信息
[root@iz2ze9ibpdra8vnyqrclsdz yum.repos.d]# docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535 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先去本地找
hello-world
的镜像,发现没有,再去仓库中找,然后下载到本地,使用该镜像创建一个容器,最后运行。所以我们想要运行一个镜像时,不用管本地有没有这个镜像,只有你处于连网的状态,我们就可以从中央仓库下载下来这个镜像。
本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!