在CentOS7上安裝Docker環(huán)境要注意哪些事項(xiàng)

這篇文章主要介紹“在CentOS7上安裝Docker環(huán)境要注意哪些事項(xiàng)”,在日常操作中,相信很多人在在CentOS7上安裝Docker環(huán)境要注意哪些事項(xiàng)問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”在CentOS7上安裝Docker環(huán)境要注意哪些事項(xiàng)”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

創(chuàng)新互聯(lián)是專(zhuān)業(yè)的德清網(wǎng)站建設(shè)公司,德清接單;提供成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行德清網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!

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

docker的安裝要求64位系統(tǒng)且內(nèi)核版本大于3.10。所以如果是centos的話,必須安裝centos7.0或以上版本。
我們這里使用的是centos7.2 mininul。

uname -r
3.10.0-327.28.3.el7.x86_64

安裝docker前執(zhí)行一下全系統(tǒng)的軟件版本升級(jí):
yum -y update

1.配置yum軟件庫(kù)

為保證安裝的成功,首先使用yum update更新yum包,表示我的好多yum包都需要更新,1500+的包,如果你像我一樣好久沒(méi)有更新過(guò),那就耐心等候吧。
然后在yum軟件庫(kù)中新增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軟件庫(kù)的配置之后,安裝也變得異常的簡(jiǎn)單,只需要以下一句即可:

# yum install docker-engine

3.啟動(dòng)docker
一切就緒之后,使用start命令來(lái)啟動(dòng)docker守護(hù)進(jìn)程:

# service docker start

4.輸出hello-world
程序員貌似跟hello-world有仇,有事兒沒(méi)事就打印人家一下,玩docker咱們當(dāng)前也不例外,先來(lái)個(gè)hello-world吧,這里的基本原理是利用人家已經(jīng)寫(xiě)好的hello-world鏡像,下載到本地,然后把他運(yùn)行起來(lái)~

使用以下命令:

# docker run hello-world

然后控制端會(huì)輸出類(lèi)似于如下的信息,就證明我們的docker環(huán)境安裝成功了~

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

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'.

然后我又來(lái)了一次就好了,應(yīng)該是墻的原因吧,看著是網(wǎng)絡(luò)訪問(wèn)失敗了~

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/

設(shè)置為自啟動(dòng):

chkconfig docker on

調(diào)整docker數(shù)據(jù)目錄:

把一個(gè)獨(dú)立的數(shù)據(jù)分區(qū)設(shè)置為docker數(shù)據(jù)目錄,需手工把docker原目錄的數(shù)據(jù)都移到新的存儲(chǔ)分區(qū)上去,然后以新的存儲(chǔ)分區(qū)掛載到/var/lib/docker目錄下。

service docker stop

拷數(shù)據(jù)及掛分區(qū):

service docker start

4、創(chuàng)建一個(gè)專(zhuān)用的docker group

docker是需要使用root權(quán)限運(yùn)行的,但仍然可以通過(guò)創(chuàng)建一個(gè)專(zhuān)用的用戶組的方式,讓一個(gè)具備sudo權(quán)限的普通用戶管理docker服務(wù)。

復(fù)制代碼 代碼如下:

# groupadd docker
# usermod -ag docker bjxtb

退出當(dāng)前會(huì)話,重新登錄后使用bjxtb直接管理docker:

$ docker run hello-world

運(yùn)行一個(gè) docker 容器:

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

我們可以看到,centos 容器已經(jīng)被啟動(dòng),并且我們得到了 bash 提示符。在 docker 命令中我們使用了 “-i 捕獲標(biāo)準(zhǔn)輸入輸出”和 “-t 分配一個(gè)終端或控制臺(tái)”選項(xiàng)。若要斷開(kāi)與容器的連接,輸入 exit。

[root@cd05639b3f5c /]# cat /etc/redhat-release
centoslinux release 7.0.1406(core)
[root@cd05639b3f5c /]#exit
exit
[root@localhost ~]#

我們還可以搜索基于 fedora 和 ubuntu 操作系統(tǒng)的容器。

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

顯示當(dāng)前正在運(yùn)行容器的列表

到此,關(guān)于“在CentOS7上安裝Docker環(huán)境要注意哪些事項(xiàng)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

網(wǎng)頁(yè)題目:在CentOS7上安裝Docker環(huán)境要注意哪些事項(xiàng)
文章源于:http://bm7419.com/article0/pcdiio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、靜態(tài)網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)、外貿(mào)建站、軟件開(kāi)發(fā)、全網(wǎng)營(yíng)銷(xiāo)推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司