docker 把容器commit成镜像
该方法是使用docker commit 命令,其命令格式为:
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
主要参数选项包括:
- -a ,–author=”” 作者信息
- -m,–message=”” 提交信息
- -p,–pause=true 提交是暂停容器运行
docker commit +参数 模板容器 构成的镜像
举例:
[root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker run -dit --name aa centos:latest Unable to find image 'centos:latest' locally latest: Pulling from library/centos 8ba884070f61: Pull complete Digest: sha256:8d487d68857f5bc9595793279b33d082b03713341ddec91054382641d14db861 Status: Downloaded newer image for centos:latest c29d6e5a467c11ab34cd4bfd6f3484539711c361310796211db8d1b271ae51f8 [root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c29d6e5a467c centos:latest "/bin/bash" 2 minutes ago Up 2 minutes aa 957f22f13326 java:latest "java -jar -Xms256m …" 23 hours ago Up About an hour 0.0.0.0:8090->8090/tcp mobile [root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker commit -a "sjj" -m "这是项目一的第一个版本镜像" aa bb:v1.0 4sha256:3b8d26737bcb99aa12ef55c6e9620720b0ad85ecdee9cd52fbb5d5e1a2da2591 [root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE bb v1.0 3b8d26737bcb 12 seconds ago 202MB centos latest 9f38484d220f 3 weeks ago 202MB java latest d23bdf5b1b1b 2 years ago 643MB
[root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker image inspect bb:v1.0 [ { "Id": "sha256:3b8d26737bcb99aa12ef55c6e9620720b0ad85ecdee9cd52fbb5d5e1a2da2591", "RepoTags": [ "bb:v1.0" ], "RepoDigests": [], "Parent": "sha256:9f38484d220fa527b1fb19747638497179500a1bed8bf0498eb788229229e6e1", "Comment": "这是项目一的第一个版本镜像", "Created": "2019-04-09T10:30:00.512844021Z", "Container": "c29d6e5a467c11ab34cd4bfd6f3484539711c361310796211db8d1b271ae51f8", "ContainerConfig": { "Hostname": "c29d6e5a467c", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": true, "OpenStdin": true, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/bash" ], "ArgsEscaped": true, "Image": "centos:latest", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.build-date": "20190305", "org.label-schema.license": "GPLv2", "org.label-schema.name": "CentOS Base Image", "org.label-schema.schema-version": "1.0", "org.label-schema.vendor": "CentOS" } }, "DockerVersion": "18.09.2", "Author": "sjj", "Config": { "Hostname": "c29d6e5a467c", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": true, "OpenStdin": true, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/bash" ], "ArgsEscaped": true, "Image": "centos:latest", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.build-date": "20190305", "org.label-schema.license": "GPLv2", "org.label-schema.name": "CentOS Base Image", "org.label-schema.schema-version": "1.0", "org.label-schema.vendor": "CentOS" } }, "Architecture": "amd64", "Os": "linux", "Size": 201782942, "VirtualSize": 201782942, "GraphDriver": { "Data": { "MergedDir": "/var/lib/docker/overlay2/71f5125fb1a5fe97559dce70e96bcef490ca3b80e84f89304e9cf31970633b44/merged", "UpperDir": "/var/lib/docker/overlay2/71f5125fb1a5fe97559dce70e96bcef490ca3b80e84f89304e9cf31970633b44/diff", "WorkDir": "/var/lib/docker/overlay2/71f5125fb1a5fe97559dce70e96bcef490ca3b80e84f89304e9cf31970633b44/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:d69483a6face4499acb974449d1303591fcbb5cdce5420f36f8a6607bda11854" ] }, "Metadata": { "LastTagTime": "2019-04-09T18:30:00.521570076+08:00" } } ]
**** 好看的皮囊千篇一律,有趣的灵魂万里挑一 **** 好评点赞 !!!!!!!!!!!!!!!!!!!!!!!!!!!