04-docker-commit构建自定义镜像
主旨
linux环境
ddocker环境
容器里面的操作,当容器被销毁了就没有了
最好不要把数据存放在容器中
我们的实际需求,基础镜像很多无法满足,所以我们需要自定义构建镜像
[yunweijia@localhost ~]$ sudo docker run -it centos:7 /bin/bash
[ ]
[ ]
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255
ether 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 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[ ]
增加一个可持续运行的脚本。,新增的脚本所处位置,必须在容器中PATH的目录下方可,或者修改下PATH环境变量,不然无法在生成容器的时候指定该脚本,后面配置程序也是如此。
[ ]
while true;do echo yunweijia; sleep 5; done
[ ]
语法:docker commit 容器ID 镜像名:版本号
参数解释:
镜像名:随意,和原镜像无任何关系
版本号:随意,和原版本无任何关系
实例:
[yunweijia@localhost ~]$ sudo docker commit c84f1f4e5c37 centos:ceshi
[yunweijia@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos ceshi adeae577d8b3 13 seconds ago 359MB
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos 7 eeb6ee3f44bd 4 months ago 204MB
[yunweijia@localhost ~]$
[yunweijia@localhost ~]$ sudo docker run -d centos:ceshi /bin/bash -c yunweijia
291ac4a08a8d7f746ec7690e92241bf17c683edb2b5694fb421ba7ba067d9725
[yunweijia@localhost ~]$
[yunweijia@localhost ~]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
291ac4a08a8d centos:ceshi "/bin/bash -c yunwei…" 8 seconds ago Up 7 seconds awesome_wiles
[yunweijia@localhost ~]$ sudo docker logs 291ac4a08a8d
yunweijia
yunweijia
yunweijia
yunweijia
yunweijia
yunweijia
[yunweijia@localhost ~]$ # 说明我们指定的脚本在容器中运行呢
~]$ sudo docker exec -it 291ac4a08a8d /bin/bash
/]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.3 netmask 255.255.0.0 broadcast 172.17.255.255
ether 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 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
/]#
发表评论