參考docker官網安裝文檔以及阿里雲安裝文檔
docker官網安裝文檔地址:https://docs.docker.com/install/linux/docker-ce/centos/
阿里雲docker安裝文檔地址:https://yq.aliyun.com/articles/110806?spm=5176.8351553.0.0.66041991AtwfFJ
1、卸載舊版本docker(如果沒有安裝過自然不用卸載啦,跳過這一步)
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
2、安裝必要的一些系統工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
3、添加軟件源信息(這里使用國內的阿里雲,docker官網上國外地址網速太慢)
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4、更新並安裝 Docker-CE(個人版,如果是企業安裝也可以選擇企業版,參考官網文檔:https://docs.docker.com/install/linux/docker-ee/centos/)
sudo yum makecache fast
sudo yum -y install docker-ce
5、開啟Docker服務
sudo systemctl start docker //centos7開啟服務是systemctl,centos6是service
6、檢查docker版本
docker version
//執行上面命令,出現下面結果
[root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 19.03.4
API version: 1.40
Go version: go1.12.10
Git commit: 9013bf583a
Built: Fri Oct 18 15:52:22 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.4
API version: 1.40 (minimum version 1.12)
Go version: go1.12.10
Git commit: 9013bf583a
Built: Fri Oct 18 15:50:54 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
7、運行docker測試項目
sudo docker run hello-world
//運行上面命令,得到下面結果
[root@localhost ~]# sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f 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/
重點來啦!!!!
重點來啦!!!!
重點來啦!!!!
8、配置阿里雲鏡像加速器
(1)打開鏈接:https://cr.console.aliyun.com
(2)注冊賬號,或者使用支付寶賬號登陸
(3)登陸后進入下面頁面
(4)選擇<鏡像加速器>菜單,右邊會顯示你專屬的鏡像加速器地址,然后選擇centos,直接復制上圖紅框中的代碼在終端中運行即可,或者復制下面命令,修改為自己的鏡像加速地址后運行
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["寫改為自己的鏡像加速地址"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
到此centos7系統下安裝docker已經完成!!!