在CentOS 7上安裝Docker環境

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

如下操做均在root用戶下完成程序員

1.配置yum軟件庫

爲保證安裝的成功,首先使用yum update更新Yum包,表示個人好多yum包都須要更新,1500+的包,若是你像我同樣很久沒有更新過,那就耐心等候吧。docker

而後在yum軟件庫中新增docker的配置:ubuntu

#  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軟件庫的配置以後,安裝也變得異常的簡單,只須要如下一句便可:centos

# yum install docker-engine

3.啓動Docker

一切就緒以後,使用start命令來啓動Docker守護進程:bash

# service docker start

4.輸出hello-world

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

使用如下命令:app

# docker run hello-world

而後控制端會輸出相似於以下的信息,就證實咱們的docker環境安裝成功了~ide

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

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/
相關文章
相關標籤/搜索