A little while ago I set up a local repository for some of my custom containers, they all seem to work fine and when they're running if I issue a docker image ls I can see the repository image and the tag is latest
Now, I recently made a chance to one of those images, and when I pushed it to the repository I tagged it :v1.0 in an effort to have some sort of versioning.
The problem is that it seems like when I try to deploy a container based on that image name, when it defaults to latest that doesn't mean the v1.0 image, despite that one being the most recent one pushed.
Did I mess up by not tagging my original images with a version, or is there a different way to accomplish what I'm trying to do?
Related
I am going through a books and came across this line:
Whereas a tag can only be applied to a single image in a repository, a single image can have several tags. For example, the Java repository on Docker Hub maintains the following tags: 7, 7-jdk, 7u71, 7u71-jdk, openjdk-7, and openjdk-7u71. All these tags are applied to the same image.
My question is: why will a single image have several tags? What is the purpose of tagging the same image with different tags?
In my opinion there are mainly two reasons.
First of all, it is for convenience, so you may give multiple aliases to the same images.
But you can give other (special) tags to images in order to push it to a different registry.
Suppose (for example) you are using microk8s and you enabled the registry service. To push a local image of yours, you have to apply it with a tag formerly named localhost:32000/my-image:my-tag.
In that scenario your image will have two tags my-image:my-tag and localhost:32000/my-image:my-tag. So, to push it to microk8s registry the only thing you will have to do is to issue the command git push localhost:32000/my-image:my-tag (the image tag will be parsed to get the URI of the registry to push to).
The above concept, obviously, can be applied to any other remote registry.
You can use multiple tags for all sorts of purposes. The most popular one is to have a "latest" image, for example.
Imagine you're pulling the latest ubuntu image.
That would be "docker pull ubuntu:latest". Try pulling ubuntu:20.04 - you'll find out you have already pulled the image.
NOTE: After a while, ubuntu:latest won't be the same a ubuntu:20.04 anymore, but to the newest tag. However, you'll always have a pointer to the latest version of the ubuntu image and wherever you're using it, you won't need to change the tags.
I'm working on CI tool to build new docker images and then push them to our registry in AWS ECR. However, I just noticed that I have built an image several times an image that didn't change. This means that I have created and push several tags for the same image id. I would like to avoid spamming our registry with redundant tags. my question is:
is there a way to check the registry for an image id before pushing the image that I just built?
There are multiple ways to handle this
case 1(which i don't feel is right)
check for the tags in ECR as a precheck and then build image
case 2(which we use currently)
make use of git hook to trigger the pipeline(or build) only when there is a change into the repository
Also on a sidenote, tags with commit hash or datetimestamp would be helpful if its only the binary that keeps changing over the course to keep track of the dependencies which this dockerfile is depended over.
AWS ECS service points to a Task Definition, which holds a name of docker image, including a tag.
So when I create a new version of my docker image I have 2 possibilities:
Update Task definition to the new version and then update Service to point to the new revision of Task Definition
Use some tag to point to the last version, let's say "current" tag will always point to the last version, Task Definition will contain "my-image:current" and then I need just restart ECS service
What is better and why?
Use a unique tag for every build, and update the task definition to point at the new tag (your first option).
The big problem you'll run into is that, in general, Docker-based systems will try to avoid pulling an image they already have. If you restart the service, but the node it restarts on sees it already has my-image:current, it will just re-run it without pulling the updated version. It seems like it can work – How does "latest" tag work in an ECS task definition and container instances pulling from ECR? includes a setup which appears to work – but it's a little hard to tell just from looking at things what exact version you have in use.
A second good reason to avoid a "current" or "latest" tag is to have the ability to roll back. If you use, for example, a timestamp-based tagging system, you deploy build 20200323, and it doesn't work, it's very easy to reset the task definition back to build 20200322 to get back to yesterday's code while your developers debug things. If it was "current" yesterday, and it's "current" today, it's a lot harder to figure out what "not-current" should be.
I don't know if this is intended behavior or bug in GCR.
Basically I tried do it like that:
Create image from local files using Docker on Windows (Linux based image).
Before creating image I delete all local images with the same name/tag.
Image is tagged like repostiory/project/name:v1
When testing locally image have correct versions of executables (docker run imageID).
Before pushing image to GCR I delete all images from GCR with the same tag/name.
When Trying to pull new image from GCR to example kubernetes it pull the first (ever) image uploaded under particular tag.
I want to reuse the same tag to not change config file with every test and I don't really need to store previous versions of images.
It sounds like you're hitting the problem described in kubernetes/kubernetes#42171.
tl;dr, the default pull policy of kubernetes is broken by design such that you cannot reuse tags (other than latest). I believe the guidance from the k8s community is to use "immutable tags", which is a bit of an oxymoron.
You have a few options:
Switch to using the latest tag, since kubernetes has hardcoded this in their default pull policy logic (I believe in an attempt to mitigate the problem you're having).
Never reuse a tag.
Switch to explicitly using the PullAlways ImagePullPolicy. If you do this, you will incur a small overhead, since your node will have to check with the registry that the tag has not changed.
Switch to deploying by image digest with the PullIfNotPresent ImagePullPolicy. A more detailed explanation is in the PR I linked, but this gets you the best of both worlds.
I have a Dockerfile something like follows:
FROM openjdk:8u151
# others here
I have 2 questions about the base image:
1. How to get the tags?
Usually, I get it from dockerhub, let's say openjdk:8u151, I can get it from dockerhub's openjdk repository.
If I could get all tags from any local docker command, then I no need to visit web to get the tags, really a little low efficiency?
2. Will the base image safe?
I mean if my base image always there?
Look at the above openjdk repo, it is an offical repo.
I found there is only 8u151 left for me to choose. But I think there should be a lots of jdk8 release during the process, so should also a lots of jdk8 images there, something like 8u101, 8u163 etc.
So can I guess the maintainer will delete some old images for openjdk?
Then if this happen, how my Dockerfile work? I should always change my base image if my upstream delete there image? Really terrible for me to maintain such kind of thing.
Even if the openjdk really just generate one release of jdk8. My puzzle still cannot be avoided, as dockerhub really afford the delete button for users.
What's the best practice, please suggest, thanks.
How to get the tags?
See "How to list all tags for a Docker image on a remote registry?".
The API is enough
For instance, visit:
https://registry.hub.docker.com/v2/repositories/library/java/tags/?page_size=100&page=2
Will the base image safe?
As long as you save your own built image in a registry (eithe rpublic one, or a self-hosted one), yes: you will be able to at least build new images based on the one you have done.
Or, even if the base image disappears, you still have its layers in your own image, and can re-tag it (provided the build cache is available).
See for instance "Is there a way to tag a previous layer in a docker image or revert a commit?".
See caveats in "can I run an intermediate layer of docker image?".