[root@qiaoyanjie /]# docker image inspect redis:latest #docker inspect id/name都可以
[
{
"Id": "sha256:7614ae9453d1d87e740a2056257a6de7135c84037c367e1fffa92ae922784631",
"RepoTags": [
"redis:latest"
],
"RepoDigests": [
"redis@sha256:db485f2e245b5b3329fdc7eff4eb00f913e09d8feb9ca720788059fdc2ed8339"
],
"Parent": "",
"Comment": "",
"Created": "2021-12-21T12:42:49.755107412Z",
"Container": "13d25f53410417c5220c8dfe8bd49f06abdbcd69faa62a9b877de02464bb04a3",
"ContainerConfig": {
"Hostname": "13d25f534104",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"6379/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.12",
"REDIS_VERSION=6.2.6",
"REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-6.2.6.tar.gz",
"REDIS_DOWNLOAD_SHA=5b2b8b7a50111ef395bf1c1d5be11e6e167ac018125055daa8b5c2317ae131ab"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"redis-server\"]"
],
"Image": "sha256:e093f59d716c95cfce82c676f099b960cc700432ab531388fcedf79932fc81ec",
"Volumes": {
"/data": {}
},
"WorkingDir": "/data",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "20.10.7",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"6379/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.12",
"REDIS_VERSION=6.2.6",
"REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-6.2.6.tar.gz",
"REDIS_DOWNLOAD_SHA=5b2b8b7a50111ef395bf1c1d5be11e6e167ac018125055daa8b5c2317ae131ab"
],
"Cmd": [
"redis-server"
],
"Image": "sha256:e093f59d716c95cfce82c676f099b960cc700432ab531388fcedf79932fc81ec",
"Volumes": {
"/data": {}
},
"WorkingDir": "/data",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 112691373,
"VirtualSize": 112691373,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/bf1060ab9ddbf5b9c6a11a9b2b09fba193ce7e049732c218fc58139762c54a33/diff:/var/lib/docker/overlay2/476f68861a57014cf93befcf976ccf617bc8e5d2e3a0b13e25cd9d9375b87640/diff:/var/lib/docker/overlay2/211ec5b7dc971f41c597ad842b2751b9f1b7cf420611e1386be8330db3e6d828/diff:/var/lib/docker/overlay2/9a117915c240aacd94f6c4e085d139a740eab2707115c5387a93fecfbd219ae1/diff:/var/lib/docker/overlay2/4338c66d8000c0678bbf6e0f084f66413934613c477162fa2ebdf19d41f9cf9a/diff",
"MergedDir": "/var/lib/docker/overlay2/17e0ff1851b2f8ff7e03f5a5f4a234bdfe878467360ea11d1bf12f93a697e7f1/merged",
"UpperDir": "/var/lib/docker/overlay2/17e0ff1851b2f8ff7e03f5a5f4a234bdfe878467360ea11d1bf12f93a697e7f1/diff",
"WorkDir": "/var/lib/docker/overlay2/17e0ff1851b2f8ff7e03f5a5f4a234bdfe878467360ea11d1bf12f93a697e7f1/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:2edcec3590a4ec7f40cf0743c15d78fb39d8326bc029073b41ef9727da6c851f",
"sha256:9b24afeb7c2f21e50a686ead025823cd2c6e9730c013ca77ad5f115c079b57cb",
"sha256:4b8e2801e0f956a4220c32e2c8b0a590e6f9bd2420ec65453685246b82766ea1",
"sha256:529cdb636f61e95ab91a62a51526a84fd7314d6aab0d414040796150b4522372",
"sha256:9975392591f2777d6bf4d9919ad1b2c9afa12f9a9b4d260f45025ec3cc9b18ed",
"sha256:8e5669d8329116b8444b9bbb1663dda568ede12d3dbcce950199b582f6e94952"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
commit镜像
docker commit 提交容器成为一个新的副本
docker commit -m="提交的描述信息" -a="作者" 容器id 目标镜像名:[tag]
# 1、启动一个默认的tomcat
[root@qiaoyanjie /]# docker run -d --name tomcat01 -p 3345:8080 tomcat
47362e18c0f7cde0860be038516a7424d4d120ae035b8a8081855bd33d9637eb
[root@qiaoyanjie /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
47362e18c0f7 tomcat "catalina.sh run" 5 seconds ago Up 4 seconds 0.0.0.0:3345->8080/tcp tomcat01
a0fc9465cc87 portainer/portainer "/portainer" 2 hours ago Up 2 hours 0.0.0.0:8088->9000/tcp portainer01
89af9d4d7f34 elasticsearch:7.6.2 "/usr/local/bin/dock…" 14 hours ago Up 14 hours 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch02
c4ac304a64a3 elasticsearch:7.6.2 "/usr/local/bin/dock…" 15 hours ago Exited (143) 14 hours ago elasticsearch01
10987a6f0593 nginx "/docker-entrypoint.…" 7 days ago Up 22 hours 0.0.0.0:3344->80/tcp nginx01
# 2、进入容器,官方镜像默认 webapps 下面是没有文件的! 自己拷贝进去文件。
[root@qiaoyanjie /]# docker exec -it 47362e18c0f7 /bin/bash
root@47362e18c0f7:/usr/local/tomcat# ls
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt bin conf lib logs native-jni-lib temp webapps webapps.dist work
root@47362e18c0f7:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@47362e18c0f7:/usr/local/tomcat/webapps# exit
exit
# 3、将我们操作过的容器通过commit提交为一个新的镜像!以后可直接使用。
[root@qiaoyanjie /]# docker commit -m="add webapps app" -a="Joe" 47362e18c0f7 tomcat:1.0
sha256:6a97a6c93a9fd25bcc2cee2aeb20e0c83930811adde881c3182d039a40f8b41a
[root@qiaoyanjie /]# docker images # tomcat:1.0是自己新提交的镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 1.0 6a97a6c93a9f 3 seconds ago 684MB
nginx latest 605c77e624dd 4 months ago 141MB
tomcat latest fb5657adc892 4 months ago 680MB
redis latest 7614ae9453d1 4 months ago 113MB
portainer/portainer latest 580c0e4e98b0 13 months ago 79.1MB
elasticsearch 7.6.2 f29a1ee41030 2 years ago 791MB