技术栈

主页 > 系统 >

CentOS7.2下安装Docker并运行第一个容器

要求内核版本高于3.10的64位

系统

支持Docker

[[email protected] imagedb]# uname -a

Linux

localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

[[email protected] imagedb]# more /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

使用yum安装Docker(保证主机能上网)

[[email protected] imagedb]#yum install docker

查看Docker已经安装

[[email protected] imagedb]#rpm -qa | grep docker

docker-client-1.12.6-55.gitc4618fb.el7.centos.x86_64

docker-1.12.6-55.gitc4618fb.el7.centos.x86_64

docker-common-1.12.6-55.gitc4618fb.el7.centos.x86_64

启动docker

[[email protected] imagedb]# systemctl start docker.service

查看docker版本

[[email protected] ~]# docker version

Client:

Version: 1.12.6

API version: 1.24

Package version: docker-1.12.6-55.gitc4618fb.el7.centos.x86_64

Go version: go1.8.3

Git commit: c4618fb/1.12.6

Built: Thu Sep 21 22:33:52 2017

OS/Arch: linux/amd64

Server:

Version: 1.12.6

API version: 1.24

Package version: docker-1.12.6-55.gitc4618fb.el7.centos.x86_64

Go version: go1.8.3

Git commit: c4618fb/1.12.6

Built: Thu Sep 21 22:33:52 2017

OS/Arch: linux/amd64

测试运行hello word

[[email protected] ~]# docker run hello-world

Unable to find image 'hello-world:latest' locally

Trying to pull repository docker.io/library/hello-world ...

latest: Pulling from docker.io/library/hello-world

5b0f327be733: Pull complete

Digest: sha256:1f19634d26995c320618d94e6f29c09c6589d5df3c063287a00e6de8458f8242

Hello from Docker!

This message shows that your installation appears to be working correctly.

下载并加载我们的第一个centos容器(下载时间很长)

[[email protected] ~]# docker run -i -t centos

Unable to find image 'centos:latest' locally

Trying to pull repository docker.io/library/centos ...

latest: Pulling from docker.io/library/centos

d9aaf4d82f24: Pull complete

Digest: sha256:eba772bac22c86d7d6e72421b4700c3f894ab6e35475a34014ff8de74c10872e

[[email protected] /]#

查看使用第一个容器

[[email protected] /]# more /etc/redhat-release

CentOS Linux release 7.4.1708 (Core)

[[email protected] /]# hostname

3af0e01415a4

[[email protected] /]# more /etc/host

host.conf hostname hosts hosts.allow hosts.deny

[[email protected] /]# more /etc/hosts

127.0.0.1 localhost

::1 localhost ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

172.17.0.2 3af0e01415a4

[[email protected] /]# ping www.hao123.com

PING hao123.n.shifen.com (115.239.217.167) 56(84) bytes of data.

64 bytes from 115.239.217.167 (115.239.217.167): icmp_seq=1 ttl=127 time=76.3 ms

64 bytes from 115.239.217.167 (115.239.217.167): icmp_seq=2 ttl=127 time=47.2 ms

64 bytes from 115.239.217.167 (115.239.217.167): icmp_seq=3 ttl=127 time=47.9 ms

64 bytes from 115.239.217.167 (115.239.217.167): icmp_seq=4 ttl=127 time=47.2 ms

64 bytes from 115.239.217.167 (115.239.217.167): icmp_seq=5 ttl=127 time=47.9 ms

exit退出容器(退出容器后容器就停止工作)

[[email protected] /]# exit

exit

[[email protected] ~]#

查看已经下载的镜像

[[email protected] ~]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

docker.io/centos latest 196e0ce0c9fb 7 days ago 196.6 MB

docker.io/hello-world latest 05a3bd381fc2 9 days ago 1.84 kB

责任编辑:admin     二维码分享:
本文标签: rootlocalhostdocker115.239217.167x86