如果你主机之前没有安装过Docker Engine-Community,需要先设置docker仓库,以后方便从仓库安装和更新docker。
考虑国内网络环境问题,我们优先考虑国内镜像源,我采用的是阿里云的,大家也可以试试清华大学源。
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
然后开始安装,默认是安装最新版本的。我们先体验一下最新的版本:
yum install docker-ce docker-ce-cli containerd.io
接着输入”y“,并回车继续安装。
安装好后,默认是不启动,需要我们手动去启动docker:
systemctl start docker
最后运行一个实例看看效果:
docker run hello-world
如果是第一次新安装的docker,默认是没有这个应用程序。但docker会自动去仓库拉取,然后并自行运行。
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5
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。