一、設置存儲庫
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
執行結果
已加載插件:fastestmirror, langpacks adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
二、安裝docker-ce(docker-ce是社區免費版,docker-ee是企業版)
yum install -y docker-ce
出現錯誤
獲取 GPG 密鑰失敗:[Errno 14] curl#35 - "Network file descriptor is not connected"
到http://mirrors.163.com找到對應版本
rpm --import http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
再次安裝docker-ce成功
三、啟動docker
systemctl daemon-reload && systemctl start docker
驗證
docker version
Client: Docker Engine - Community Version: 19.03.7 API version: 1.40 Go version: go1.12.17 Git commit: 7141c199a2 Built: Wed Mar 4 01:24:10 2020 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.7 API version: 1.40 (minimum version 1.12) Go version: go1.12.17 Git commit: 7141c199a2 Built: Wed Mar 4 01:22:45 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.2.13 GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc: Version: 1.0.0-rc10 GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd docker-init: Version: 0.18.0 GitCommit: fec3683
四、運行hello word!
先login(官方文檔上說運行helloword不需要login,但會出現docker: Error response from daemon: pull access denied for hell-world, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.錯誤)
[root@localhost data]# docker run hello-world Unable to find image 'hell-world:latest' locally docker: Error response from daemon: pull access denied for hell-world, repository does not exist or may require 'docker login': denied: requested access to the resource is denied. See 'docker run --help'. [root@localhost data]# docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: xxxxx Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded
運行hello-world
[root@localhost data]# docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:fc6a51919cfeb2e6763f62b6d9e8815acbf7cd2e476ea353743570610737b752 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/