大网数据广告活动
服务器运维问答

Does docker restart use the latest image or the one the container was created with?

· 52CE 我爱测

If I create a container using a tag/label docker run --name some_container -d me/my_image Update the image with docker pull me/my_image And restart the container with docker restart some_container Which version does the new conta…

问题原文

原帖链接 · Esa Varemo · CC BY-SA 3.0

If I create a container using a tag/label

docker run --name some_container -d me/my_image

Update the image with

docker pull me/my_image

And restart the container with

docker restart some_container

Which version does the new container use?

In docker inspect .Image gives the id of the specific image, .Config.Image gives the label.

已采纳解答

原帖链接 · Andy Shinn · CC BY-SA 3.0

It uses the image the container was created from. This is pretty easy to verify.

Lets take a look at the image ID for an outdated image:

$ docker images alpine:3.2                 
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
alpine              3.2                 137f13b3ac76        8 seconds ago       5.254 MB

Cool, now lets create a container based off that image:

$ docker create --name test alpine:3.2 sh
1011a97c6ed5dc0249eedc133d4f98197b379a40acc43d74f212a3d49f49db09

We can see the image that container is based off of:

$ docker inspect -f '{{.Image}}' test    
137f13b3ac76e253a90cc952c2b5921c41de0f56e8a5833e96f63e6f0c94f228

Now we pull an updated alpine:3.2:

$ docker pull alpine:3.2
3.2: Pulling from library/alpine
Digest: sha256:1b42caf22e8a6c00e4e7f8c0274495b815336d549317cf694e274832aecf11ed
Status: Image is up to date for alpine:3.2

See that it has a new image ID:

$ docker images alpine:3.2                 
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
alpine              3.2                 74e49af2062e        3 days ago          5.254 MB

But the container is still using the older image ID:

$ docker inspect -f '{{.Image}}' test
137f13b3ac76e253a90cc952c2b5921c41de0f56e8a5833e96f63e6f0c94f228

When you check out the images you can see the new one and the old dangling one:

$ docker images
REPOSITORY         TAG                  IMAGE ID            CREATED             VIRTUAL SIZE
<none>             <none>               137f13b3ac76        51 seconds ago      5.254 MB
alpine             3.2                  74e49af2062e        3 days ago          5.254 MB

If you tried to delete the old image you will be met with an error:

$ docker rmi 137f13b3ac76
Error response from daemon: conflict: unable to delete 137f13b3ac76 (must be forced) - image is being used by stopped container 1011a97c6ed5
Error: failed to remove images: [137f13b3ac76]

The image can be deleted once the container that is based off it is removed.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-12-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。