
在centos7上我們可以通過(guò)yum來(lái)安裝docker
1.確保你擁有管理員權(quán)限,需要可以使用sudo或者root的命令的權(quán)限。
2.需要將你的yum的包升級(jí)到最新的狀態(tài)。
sudo yum update
3.為你的yum添加一個(gè)repo文件。在centos7下面您可以直接運(yùn)行下面的代碼。
cat >/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
在shell狀態(tài)下可以直接粘貼復(fù)制。這個(gè)repo的目的就是為了讓我們的yum可以根據(jù)repo文件里提供的連接去檢索docker最新的安裝包。
4.使用yum命令安裝docker
sudo yum install docker-engine
根據(jù)提示一路確認(rèn)即可。安裝好以后會(huì)提示類似下面的話
Installed:
docker-engine.x86_64 0:1.8.2-1.el7.centos
Dependency Installed:
libcgroup.x86_64 0:0.41-8.el7
Complete!
這就說(shuō)明你的docker安裝成功了。
5.用下面的命令啟動(dòng)docker
sudo service docker start
如果你的centos里面沒(méi)有任何鏡像的話,系統(tǒng)會(huì)提示下面這句話。
Starting docker (via systemctl):
可以不用理會(huì)直接ctrl+c退出,因?yàn)闆](méi)有任何鏡像你的docker沒(méi)有什么可以啟動(dòng)的。
6.通過(guò)docker run命令自動(dòng)添加一個(gè)hello world的鏡像
docker run hello-world
運(yùn)行這條命令以后docker會(huì)先去檢索本地是否有以hello-world命名的鏡像,如果有會(huì)直接啟動(dòng),如果沒(méi)有他會(huì)去docker在互聯(lián)網(wǎng)中默認(rèn)的鏡像庫(kù)里面尋找這個(gè)hello-word的鏡像下載并安裝。安裝好以后會(huì)自動(dòng)啟動(dòng)。提示如下:
Unable to find image 'hello-world:latest' locally
Pulling repository docker.io/library/hello-world
af340544ed62: Download complete
535020c3e8ad: Download complete
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/userguide/
如果看到這樣的命令就說(shuō)明hello-world的鏡像安裝好了。
這個(gè)時(shí)候我們?cè)冁I入
service docker start
就會(huì)提示
Starting docker (via systemctl):? ? ? ? ? ? ? ? ? ? ? ? ? [? OK? ]
說(shuō)明我們的docker已經(jīng)正常的在centos上運(yùn)行了。