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

来源:互联网 发布:三国乱世盘古辅助淘宝 编辑:程序博客网 时间:2024/06/08 00:49
要求内核版本高于3.10的64位系统支持Docker
[root@localhost 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
[root@localhost imagedb]# more /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 


使用yum安装Docker(保证主机能上网)
[root@localhost imagedb]#yum install docker


查看Docker已经安装
[root@localhost 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
[root@localhost imagedb]# systemctl start docker.service


查看docker版本
[root@localhost ~]# 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
[root@localhost ~]# 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容器(下载时间很长)
[root@localhost ~]# 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
[root@3af0e01415a4 /]# 



查看使用第一个容器
[root@3af0e01415a4 /]# more /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
[root@3af0e01415a4 /]# hostname
3af0e01415a4
[root@3af0e01415a4 /]# more /etc/host
host.conf    hostname     hosts        hosts.allow  hosts.deny   
[root@3af0e01415a4 /]# 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
[root@3af0e01415a4 /]# 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退出容器(退出容器后容器就停止工作)
[root@3af0e01415a4 /]# exit
exit
[root@localhost ~]# 


查看已经下载的镜像
[root@localhost ~]# 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


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 苹果macbook开不了机怎么办 苹果7震动像拖拉机一样怎么办 win10笔记本玩lol卡怎么办 苹果笔记本密码忘了怎么办 苹果笔记本系统密码忘记了怎么办 qq加好友频繁了怎么办 淘宝买食品有问题怎么办 手机的设置图标没有了怎么办 国家创业贷款还不了会怎么办 手机mac显示:不好使.怎么办? 英雄联盟买皮肤重复怎么办 皮肤很油毛孔又粗怎么办 笔记本电脑玩英雄联盟卡怎么办 win10系统更新不动了怎么办 win7任务栏时间没了怎么办 win10桌面图标都没了怎么办 win10软件图标没了怎么办 电脑内存插板没用了怎么办 win10笔记本开不了机怎么办 cad复制东西变卡怎么办 企业网银证书过期怎么办 游戏更新网页无法正常打开怎么办 网页游戏打开说脚本错误怎么办 电脑玩游戏出现闪屏怎么办 玩游戏时出现窗口化怎么办 玩游戏时出现输入不支持怎么办 电脑玩游戏出现蓝屏怎么办 谷歌商店网页版进不去怎么办 谷歌商店为什么打不开怎么办 玩lol突然卡顿怎么办 手机上路由器管理页面打不开怎么办 苹果电脑开机页面密码打不开怎么办 逆战活动页面打不开怎么办 电脑玩lol网络卡怎么办 ios11.4qq闪退怎么办 ios11.3qq闪退怎么办 英雄联盟进入游戏界面黑屏怎么办 英雄联盟经常未响应怎么办 英雄联盟总是无响应怎么办 英雄联盟新客户端太卡怎么办 win10英雄联盟fps低怎么办