安装docker(社区版)的命令如下:
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf install docker-ce --nobest -y
systemctl start docker
systemctl enable docker
注意:需要root权限。
如果不理解,可以参看下面的详情。
一、下载docker源
在CentOS 8 和RHEL 8中已经移除了docker的源,所以需要下载:
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
注:dnf是新一代的rpm软件包管理器,替代了yum。
二、使用dnf命令安装Docker
配置好了docker源之后,就可以通过下面的命令查看可以安装的docker-ce(docker社区版)的版本:
dnf list docker-ce
安装docker:
dnf install docker-ce --nobest -y
启动docker,并设置开机自启:
systemctl start docker
systemctl enable docker
查看已安装的docker版本
docker --version
三、检测docker是否安装成功
执行命令:
docker run hello-world
出现如下提示说明安装成功:
Hello from Docker!
This message shows that your installation appears to be working correctly.
docker run hello-world命令完整打印信息:
[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:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202
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/
注:参考博客