Will Docker Container Restart Pick Up Updated Image?
When a Docker image has been updated, will restarting the running container via docker restart pick up the change? Educated guess will be no, because like restarting a process, the memory is still retained. The best way to find out is to give a try.
Step 2 : CMD while true; do echo bar; sleep 5; done
--->Running in 7fc297e12005
---> a6c04345afb9
Removing intermediate container 7fc297e12005
Successfully built a6c04345afb9
Now we have a different image. The image ID is different: a6c0. But the old image is still there:
1
2
3
4
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
example latest a6c04345afb9 24 seconds ago 125.1 MB
<none> <none> 6a56a50ef254 3 minutes ago 125.1MB
Restart the container:
1
2
$ docker restart example
example
Got bar? No still foo all the way with the log. And when you inspect the container, it still uses the old image.
So, docker restart will not pick up the changes from updated image, it will still use the old image built previously. Therefore, the correct way is to drop the container entirely and run it again:
1
2
3
4
$ docker stop example && docker rm example && docker run -d --name example example