Reputation: 6526
How to write a FROM statement in the Dockerfile that pulls the latest image from a specific Major version. Let's say there is an application that currently has three major versions: v1.7, v2.5, v3.0.5 and I want to have always the latest version of image v2. if i put in the Dockerfile statement:
FROM imagename:latest
Then I'll get build version 3.0.5 because it is the latest version. If I put:
FROM imagename:2.5
Then I'll get exact version 2.5 but will not be able to update the image with this statement once the version 2.6 becomes available.
How to set FROM statement that will get always the latest version 2 updates that will not brake backwards compatibility and stick to that major version 2.?
Upvotes: 4
Views: 1253
Reputation: 159495
Docker image tags (including both the Dockerfile FROM
line and docker run
images) are always exact matches. As a corollary, once Docker believes it has a particular image locally, it won't try to fetch it again unless explicitly instructed to.
Many common Docker images have a convention of publishing the same image under multiple tags, that sort of reflect what you're suggesting. For instance, as of this writing, for the standard python
image, python:latest
, python:3
, python:3.7
, python:3.7.0
, and python:3.7.0-stretch
all point at the same image. If you said FROM python:3
you'd get this image. But, if you already had that image, and a Python 3.8 were released, and you rebuilt without explicitly doing a docker pull
first, you'd use the same image you already had (the Python 3.7 one). If you did docker pull python:3
then you'd get the updated image but you'd have to know to do that (or tell your CI tool to do it for you).
Upvotes: 4