How to update a Docker Image

2019-04-04 02:03发布

问题:

How do I update a docker image when the official repository is updated?

How do I update custom images when I change the DockerFile, or the Dockerfile contains time sensitive informations?

Is it better practice to build new images, or to rebuild exiting ones?

What's the best way to rebuild an existing image?

What's the best way to differentiate multiple builds of the same image?

回答1:

How do I update a docker image when the official repository is updated?

If you are using the Docker Hub to create an automated build, then you can add a Repository Link which will rebuild your repo when the linked repo updates.

If you want to do the builds yourself, you could create a hacky workaround to get the notification via a link as above and rebuild a trivial repo, then use a Web Hook to notify your build system of the change.

How do I update custom images when I change the DockerFile, or the Dockerfile contains time sensitive informations?

If you are using the Docker Hub for an automated build, then changes to your BitBucket or GitHub source repo, including Dockerfile changes, will trigger a new build.

If you're building images yourself, just type docker build . in the directory where your Dockerfile resides. You can use --no-cache to force a completely fresh rebuild

Is it better practice to build new images, or to rebuild exiting ones?

That depends on who is using your images. When you build, the result is always a new image, but how you tag the result can make it seem like a replacement for the old image or something new.

What's the best way to differentiate multiple builds of the same image?

Use the :tag feature in the name, eg

ubuntu:latest
ubuntu:12.04
ubuntu:14.04
...

see https://registry.hub.docker.com/_/ubuntu/ for a complete list of all the variations on the "ubuntu" image. See the tag documentation for the complete format for a friendly image name. All tags and names are aliases for the canonical image name, that long UUID-looking string when you run docker images --no-trunc.



标签: docker