pts
pts

Reputation: 87271

How to install the same version of a docker image?

On machine A I have docker image FOO/BAR installed. How do I query the version of that image, and how do I install the same version to machine B?

Please note that on machine B I don't need the newest available version of FOO/BAR, but the same version as machine A. I don't want to keep local modifications to the image made on machine A.

Upvotes: 0

Views: 192

Answers (2)

cizixs
cizixs

Reputation: 13981

Use a tag!

docker image supports tag, which is usually used as a version number. When building an image, you can specify a tag:

docker build -t myimage:v0.1 .

Then use the same image is easy:

docker run -d myimage:v0.1 entrypoint.sh

If you do not specify a tag, and everything works fine. Because docker uses default tag latest, which can be annoying when updating and keeping them sync.

latest image can change all the time(usually with CI/CD auto-build), so easy container can use different images. If there is not what you expected, use a tag always!

Upvotes: 0

jdno
jdno

Reputation: 4364

Docker uses a tag or digest to distinguish between different versions of an image. When specifying neither a tag or a digest, all Docker commands assume that you want to use the default tag latest. But you can always be more specific.

Assuming the image comes from a registry FOO and is called BAR, there are two ways how you can pull the same version of the image: either by tag or by digest. You can only use the tag if you know that it is unique and not reused. This is often the case when using build numbers or Git hashes as tags, but if you want to be absolutely sure, use the digest.

On machine A, run docker images --digests. Look for FOO/BAR and its digest (starting with sha:).

On machine B, run the following command and replace {digest} with the digest from machine A:

docker pull FOO/BAR@{digest}

This is an example how it could look:

docker pull FOO/BAR@sha256:e4957dfd892f656ae672dfa03eb7a73f1c47bd24fc95f2231fc5ac91a76092a0

This will download the same version that is available on machine A to machine B. Since it comes from the registry, it's a fresh copy without any modifications.

Upvotes: 1

Related Questions