docker 镜像制作 commit --entrypoint
commit --entrypoint测试
替换原来镜像中的ENTRYPOINT["/bin/bash"]
docker run -it --entrypoint ./hello --name testgo3 centosgo:v1
docker run -it --entrypoint /bin/bash --name testgo4 centosgo:v2
1、编写批处理文件
-- start.sh
#!/bin/sh
/go/hello
2、批处理文件复制到容器中
docker cp start.sh 57878d8265f4:/
3、从容器生成新的镜像
docker commit -m "test message" -a "auther" -c "ENTRYPOINT /start.sh" 57878d8265f4 centosgo:v3
4、启动新的容器
docker run -it --name testgo5 centosgo:v3
Hello, world! 【执行批处理后的输出】
5、docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e1f739ac99c0 centosgo:v3 "/bin/sh -c /start.sh" 3 minutes ago Exited (0) 18 seconds ago testgo5
08d1c3926c4c centosgo:v2 "/bin/bash" 35 minutes ago Up 34 minutes testgo4
cfacbdcb7fed centosgo:v1 "./hello" 37 minutes ago Exited (0) 37 minutes ago testgo3
06359df7d8e4 centosgo:v2 "./hello" 2 days ago Exited (0) 44 minutes ago testgo2
57878d8265f4 centosgo:v1 "/bin/bash" 2 days ago Up 44 minutes testgo
6、docker inspect testgo5
[
{
"Id": "e1f739ac99c0dc74df709613fd5ed6ea034bd330bc238e8beecaa1b286ef57ce",
"Created": "2024-03-03T08:10:39.747307979Z",
"Path": "/bin/sh",
"Args": [
"-c",
"/start.sh"
],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 0,
"Error": "",
"StartedAt": "2024-03-03T08:16:28.437939494Z",
"FinishedAt": "2024-03-03T08:16:28.456083903Z"
},
"Image": "sha256:aa591c534a08be8ede3d94cd1cfa5eae41b047ec317d6bdaf18c7f816c5a1fab",
"ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/e1f739ac99c0dc74df709613fd5ed6ea034bd330bc238e8beecaa1b286ef57ce/resolv.conf",
"HostnamePath": "/mnt/sda1/var/lib/docker/containers/e1f739ac99c0dc74df709613fd5ed6ea034bd330bc238e8beecaa1b286ef57ce/hostname",
"HostsPath": "/mnt/sda1/var/lib/docker/containers/e1f739ac99c0dc74df709613fd5ed6ea034bd330bc238e8beecaa1b286ef57ce/hosts",
"LogPath": "/mnt/sda1/var/lib/docker/containers/e1f739ac99c0dc74df709613fd5ed6ea034bd330bc238e8beecaa1b286ef57ce/e1f739ac99c0dc74df709613fd5ed6ea034bd330bc238e8beecaa1b286ef57ce-json.log",
"Name": "/testgo5",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
50,
188
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/mnt/sda1/var/lib/docker/overlay2/e3e83474fa0f8c6face480c81a271abb9029bdcaca55ae5cf0613251f856fbd4-init/diff:/mnt/sda1/var/lib/docker/overlay2/bfdff046d484b63cc98b6ff6dca54e700ce402df37f906f54adf2258a40ebc84/diff:/mnt/sda1/var/lib/docker/overlay2/9860e40d215a66a8c55f45195b445913a8013d0a5a18f353e0a3645e71f99b6a/diff:/mnt/sda1/var/lib/docker/overlay2/a1df2b174cd080b176cc372c72ca691a1e6ac36bd773b196173d60d391d9780e/diff:/mnt/sda1/var/lib/docker/overlay2/g4gkn82dvbq03guqg9y1fjlr0/diff",
"MergedDir": "/mnt/sda1/var/lib/docker/overlay2/e3e83474fa0f8c6face480c81a271abb9029bdcaca55ae5cf0613251f856fbd4/merged",
"UpperDir": "/mnt/sda1/var/lib/docker/overlay2/e3e83474fa0f8c6face480c81a271abb9029bdcaca55ae5cf0613251f856fbd4/diff",
"WorkDir": "/mnt/sda1/var/lib/docker/overlay2/e3e83474fa0f8c6face480c81a271abb9029bdcaca55ae5cf0613251f856fbd4/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "e1f739ac99c0",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": null,
"Image": "centosgo:v3",
"Volumes": null,
"WorkingDir": "/go",
"Entrypoint": [
"/bin/sh",
"-c",
"/start.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "89417f19a0e13fa26985d0d10b27309a6608b7347684cda1ac22704a2350099c",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/89417f19a0e1",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "3166940b0ae0af794c9996c489449f7fc957c26d75964998253d36c101f2fe63",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]