1、先卸载旧版本的docker
[root@mxy-docker ~]# yum remove docker\
> docker-client\
> docker-client-latest\
> docker-common\
> docker-latest\
> docker-latest-logrotate\
> docker-logrotate\
> docker-engine
2、安装yum-utils包
[root@mxy-docker ~]# yum install -y yum-utils
3、添加yum仓库文件
? ? ? ? ·这里有两种方式:
? ? ? ? ·1)添加docker官方的yum仓库? ? ? ??
[root@mxy-docker ~]# yum-config-manager \
> --add-repo \
> https://download.docker.com/linux/centos/docker-ce.repo
添加仓库自:https://download.docker.com/linux/centos/docker-ce.repo
[root@mxy-docker ~]#
? ? ? ? ·2)添加阿里云的镜像docker仓库
[root@mxy-docker ~]# yum-config-manager\
> --add-repo\
> http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
添加仓库自:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@mxy-docker ~]#
? ? ? ? ·因为第二种方式安装速度较快,所以小编比较推荐
4、进入存放所有的yum仓库文件的文件夹
[root@mxy-docker ~]# cd /etc/yum.repos.d/
[root@mxy-docker yum.repos.d]# ls
CentOS-Linux-AppStream.repo CentOS-Linux-HighAvailability.repo
CentOS-Linux-BaseOS.repo CentOS-Linux-Media.repo
CentOS-Linux-ContinuousRelease.repo CentOS-Linux-Plus.repo
CentOS-Linux-Debuginfo.repo CentOS-Linux-PowerTools.repo
CentOS-Linux-Devel.repo CentOS-Linux-Sources.repo
CentOS-Linux-Extras.repo docker-ce.repo
CentOS-Linux-FastTrack.repo
5、安装docker
[root@mxy-docker yum.repos.d]# yum install docker-ce docker-ce-cli containerd.io -y
6、启动docker,并且设置docker开机启动
[root@mxy-docker yum.repos.d]# systemctl start docker
[root@mxy-docker yum.repos.d]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@mxy-docker yum.repos.d]# ps aux|grep docker
root 21599 0.2 9.4 1295128 75900 ? Ssl 20:56 0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 21748 0.0 0.1 12324 972 pts/1 S+ 20:56 0:00 grep --color=auto docker
7、测试运行一个docker容器
[root@mxy-docker yum.repos.d]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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就安装好了
|