在CentOS 7上安裝Docker環境


官網文檔:https://docs.docker.com/engine/installation/linux/centos/ ,本文大部分是照搬官方文檔寫的,如果你英文還不錯,那么就直接移步官方文檔吧,如果你英文實在是不行,那就勉強看一下本人這生澀的翻譯~

以下操作均在root用戶下完成

1.配置yum軟件庫

為保證安裝的成功,首先使用yum update更新Yum包,表示我的好多yum包都需要更新,1500+的包,如果你像我一樣好久沒有更新過,那就耐心等候吧。

然后在yum軟件庫中新增docker的配置:

#  tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

2.安裝Docker

有了yum軟件庫的配置之后,安裝也變得異常的簡單,只需要以下一句即可:

# yum install docker-engine

3.啟動Docker

一切就緒之后,使用start命令來啟動Docker守護進程:

# service docker start

4.輸出hello-world

程序員貌似跟hello-world有仇,有事兒沒事就打印人家一下,玩docker咱們當前也不例外,先來個hello-world吧,這里的基本原理是利用人家已經寫好的hello-world鏡像,下載到本地,然后把他運行起來~

使用以下命令:

# docker run hello-world

然后控制端會輸出類似於如下的信息,就證明我們的docker環境安裝成功了~

在這里,我第一次失敗了~顯示:

Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull&service=registry.docker.io: net/http: TLS handshake timeout.
See 'docker run --help'.

然后我又來了一次就好了,應該是牆的原因吧,看着是網絡訪問失敗了~

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete 
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
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.
 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 Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM