声明:本文乃“运维家”原创,转载请注明出处,更多内容请关注公众号“运维家”。

主旨
linux环境ddocker环境
容器里面的操作,当容器被销毁了就没有了最好不要把数据存放在容器中我们的实际需求,基础镜像很多无法满足,所以我们需要自定义构建镜像
[yunweijia@localhost ~]$ sudo docker run -it centos:7 bin/bash
[root@c84f1f4e5c37 ]# yum -y install net-tools[root@c84f1f4e5c37 ]# ifconfigeth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)RX packets 8 bytes 648 (648.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0loop txqueuelen 1000 (Local Loopback)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@c84f1f4e5c37 ]#
增加一个可持续运行的脚本。,新增的脚本所处位置,必须在容器中PATH的目录下方可,或者修改下PATH环境变量,不然无法在生成容器的时候指定该脚本,后面配置程序也是如此。
[root@c84f1f4e5c37 ]# vi usr/bin/yunweijiawhile true;do echo yunweijia; sleep 5; done[root@c84f1f4e5c37 /]# exit # 退出容器
语法:docker commit 容器ID 镜像名:版本号参数解释:镜像名:随意,和原镜像无任何关系版本号:随意,和原版本无任何关系实例:[yunweijia@localhost ~]$ sudo docker commit c84f1f4e5c37 centos:ceshi[yunweijia@localhost ~]$ sudo docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos ceshi adeae577d8b3 13 seconds ago 359MBhello-world latest feb5d9fea6a5 4 months ago 13.3kBcentos 7 eeb6ee3f44bd 4 months ago 204MB[yunweijia@localhost ~]$
[yunweijia@localhost ~]$ sudo docker run -d centos:ceshi bin/bash -c yunweijia291ac4a08a8d7f746ec7690e92241bf17c683edb2b5694fb421ba7ba067d9725[yunweijia@localhost ~]$[yunweijia@localhost ~]$ sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES291ac4a08a8d centos:ceshi "/bin/bash -c yunwei…" 8 seconds ago Up 7 seconds awesome_wiles
[yunweijia@localhost ~]$ sudo docker logs 291ac4a08a8dyunweijiayunweijiayunweijiayunweijiayunweijiayunweijia[yunweijia@localhost ~]$ # 说明我们指定的脚本在容器中运行呢
[yunweijia@localhost ~]$ sudo docker exec -it 291ac4a08a8d /bin/bash[root@291ac4a08a8d /]# ifconfigeth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 172.17.0.3 netmask 255.255.0.0 broadcast 172.17.255.255ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet)RX packets 8 bytes 648 (648.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0loop txqueuelen 1000 (Local Loopback)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@291ac4a08a8d /]#
文章转载自运维家,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




