在CentOS 7上安裝Docker環境的方法與注意事項_docker

來源:互聯網
上載者:User

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

以下操作均在root使用者下完成

docker的安裝要求64位系統且核心版本大於3.10。所以如果是centos的話,必須安裝CentOS7.0或以上版本。
我們這裡使用的是CentOS7.2 mininul。

uname -r
3.10.0-327.28.3.el7.x86_64

安裝docker前執行一下全系統的軟體版本升級:
yum -y update

1.配置yum軟體庫

為保證安裝的成功,首先使用yum update更新Yum包,表示我的好多yum包都需要更新,1500+的包,如果你像我一樣好久沒有更新過,那就耐心等候吧。
然後在yum軟體庫中新增docker的配置:

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

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' locallydocker: 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' locallylatest: Pulling from library/hello-worldc04b14da8d14: Pull complete Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9Status: Downloaded newer image for hello-world:latestHello 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 bashShare images, automate workflows, and more with a free Docker Hub account: https://hub.docker.comFor more examples and ideas, visit: https://docs.docker.com/engine/userguide/

設定為自啟動:

chkconfig docker on

調整docker資料目錄:

把一個獨立的資料分區設定為docker資料目錄,需手工把docker原目錄的資料都移到新的儲存分區上去,然後以新的儲存分區掛載到/var/lib/docker目錄下。

service docker stop

拷資料及掛分區:

service docker start

4、建立一個專用的docker group

docker是需要使用root許可權啟動並執行,但仍然可以通過建立一個專用的使用者組的方式,讓一個具備sudo許可權的普通使用者管理docker服務。

複製代碼 代碼如下:

# groupadd docker
# usermod -aG docker bjxtb

退出當前會話,重新登入後使用bjxtb直接管理docker:

$ docker run hello-world

運行一個 Docker 容器:

[root@localhost ~]# docker run -i -t centos /bin/bash[root@dbf66395436d /]#

我們可以看到,CentOS 容器已經被啟動,並且我們得到了 bash 提示符。在 docker 命令中我們使用了 “-i 捕獲標準輸入輸出”和 “-t 分配一個終端或控制台”選項。若要斷開與容器的串連,輸入 exit。

[root@cd05639b3f5c /]# cat /etc/RedHat-releaseCentOSLinux release 7.0.1406(Core)[root@cd05639b3f5c /]#exitexit[root@localhost ~]#

我們還可以搜尋基於 Fedora 和 Ubuntu 作業系統的容器。

[root@localhost ~]# docker search ubuntu[root@localhost ~]# docker search fedora

顯示當前正在運行容器的列表

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.