1、基于已有镜像的容器创建
该方法使用docker commit命令
命令格式docker commit [options] container [repository[:tag]]
主要选项包括:
-a , –author=”“:作者信息;
-c , –change=[] :
-m , –message=”” :提交信息;
-p , –pause=true :提交时暂停容器运行。
下面的例子容器使用的主机的网络;端口为1022
# docker run --privileged -i -d --net host --name test ssh1
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c63818d0116 a048e7bbfdd7 "/usr/sbin/sshd -D" 3 hours ago Up 3 hours test
# ssh 127.0.0.1 -p 1022
# touch a
# docker commit -m "added a file a to /root/" -a test 1c63818d0116 test:0.1
sha256:e5adfe2bce18e1a35cc4d583a446dac7ffb7e6258a9719ba05fe036a4bf66e82
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test 0.1 e5adfe2bce18 32 seconds ago 296MB