Docker get previous image with FROM - docker

Is it possible with Docker to get a previous version of Docker image(not the current one), for example:
FROM base:previous
or something like this. Unfortunately, I don't know this image digest.

In your example previous is the tag of the image. If you know the tag of the older image just write that.
As an example the official mysql image (https://hub.docker.com/_/mysql/) lists several tags ranging from 5.5 to 8.0
So I can start an instance of mysql 5.5 using
docker run mysql:5.5
You could also do that in your Dockerfile, if the older version is 1.0 you would do:
FROM base:1.0
If you don't know which tag you used previously you might be able to find it if you list all your images locally
docker images
Good luck!

Related

Updating container on VM. How?

I specified a docker image when creating a small VM. Because of this feature, I expected a fairly hands-off way of updating the container to the latest image, but I can't find any documentation on how to do that, or at least a method that works. What the documentation says is that updating the configuration will cause the container to be updated to the latest image and the VM will be stopped & restarted, but this doesn't happen.
I've only been able to update the container by using the Cloud shell from the container registry page. Am I missing a more obvious way to do this?
Docker Tags
The version of the image is specified in the tag.
If you want the most recent, use the latest tag.
Otherwise, a version can be specified.
Example:
fedora/httpd:version1.0 will grab fedora image with version1.0.
fedora/httpd:latest will grab the latest fedora image.
Check what versioning format your image is using, and specify a version when pulling the image.
Updating your container to use newest image
To do this, you likely need to just stop the container, specify the image you want to use, and run the new container.
The key here is to trigger a new pull from the registry. If you are using the latest tag, the latest image should be pulled from the registry. Your important data/configuration should all be made persistent through volume mounting, etc. So you should just be able to plug-and-play with this new image.
If you are looking for the simplest way, maybe try writing a script to stop your running container, pull the latest image, and run this image.
It is slightly challenging to give an exact answer on this issue because there a couple ways to go about it.
Documentation for Docker Pull and Docker Tag
Use Tag for image instead of latest.
use something like this
Image: name_of_imgae:1.0

Docker image versioning with docker stack

I've setup a staging and a production server. The flow is as follows. I develop and push my new image to the staging registry. There the code is tested and if everything fits I want to push the image to the production server. I also want to use versioning. I thought about incrementing the image tag.( Not just ass latest) I deploy my application with docker stack and a compose file.
Now I want to ask about a best practice.
Example:
current image: xyz:0.1
new image: xyz:0.2
In my compose file I referance the image xyz:auto_lastest_version_here
I want to be able to see the version string and not just the latest Tag.
Is there already a mechanism or a way to reduce an update to docker pull - > pull the latest version available
stack deploy ... to update the specific container.
EDIT: I guess I can write a script where I extract the latest Tag from the images and refer the this by using an env var in my compose file. I just thought there might be an easier way or standard way provided by docker.
Image repository names and tags are just strings attached to a blob which is the actual image data. Docker and the docker registry don't really have a concept of the most recent version of a blob -- the ":latest" tag doesn't even have internal significance - it's just a string which is used by default when building, and there's nothing preventing you from tagging an older image as :latest.
Fortunately, you can tag an image with multiple tags, and that provides a reasonable solution. For me, I tag with a string identifying the version I want on my production server, like ":live" or ":production", in addition to tagging with the actual version number. Thus, lets say you have images myimage:1.0.0, myimage:1.0.1, and myimage:1.1.0, you could run:
docker tag "myimage:1.1.0" "myimage:production"
...to add a production tag to it. The stack file you deploy on the production server would always then refer to myimage:production.
The real advantage to that is that if users start complaining about problems when you switch to 1.1.0, you can simply tag myimage:1.0.1 as myimage:production and redeploy, and it would switch back to the older version.
Not sure if this is the "best" practice, but it's the one I use.

how to keep docker images if pulling newer image

I'm using some docker images, which I have pulled from a registry:
docker pull registry.example.com/project/backend:latest
docker pull registry.example.com/project/frontend:latest
Now there is a new version on the server registry. If I do a new pull, I will overwrite the current images. But I need to keep the current working images in case I do get some problems with the newest latest images.
So, how do I create a kind of backup of my running backend:latest and frontend:latest? After that I can pull the latest latest image and in case I need to, I can use the old working images...
To keep the current image on your local environment you can use docker tag
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
For example:
docker tag registry.example.com/project/backend:latest registry.example.com/project/backend:backup
Then when you pull the latest, the registry.example.com/project/backend:backup still existing
Pulling an image never deletes an existing image. However, if you have an image with the same name, the old image will become unnamed, and you'll have to refer to it by its image ID.
You've now seen the downside to using :latest tags. This is why it is better to reference an image by a specific version tag that the maintainer won't re-push.
First, you shouldn't be using latest in production environments. Rather define a tag you confirmed working.
And instead of executing stuff in an image to set it up, you should write a Dockerfile and make the installation repeatable and create your local image. That's actually one of the main reasons why docker is used.

How can I retrieve an older image for Docker instead of latest?

What command(s) do I have to run to retrieve an older image of a software offered in Docker?
I have problems with the latest image of localstack so I though I could try older versions to see what happens. However, I saw a comment in an issue mentioning editing the YAML file this way:
image: localstack/localstack:0.9
but no other info... (it was not the point of the issue, so it's understandable).
I've been looking around and saw many posts about getting the latest image (i.e. docker update ...), but nothing that would allow me to go back in time except for images that I would happen to already have.
Just the change above had absolutely no effect. I'm wondering how can I get Docker to download an older image so I can run that older one instead of the latest? I'm also wondering about how to find a list of available tags for a given docker to make sure I use a version that actually exists.
You should look for existing tags at desired repo's hub.
If you are using docker-compose the correct way to do it is:
image: <image>:<tag>
If no tag was found then it is not available or does not exist.
Here are tags available at localstack hub

Find out Docker image tag of image

Is there a way to get the tag/version of a Docker image that has been pulled weeks back using the latest tag?
A couple of months back I pulled gitlab/gitlab-ce:latest and there were new versions on Docker Hub meanwhile. I would like to know what exact version I pulled. It could for instance be the version 10.3.9-ce.0. The current tag of latest points to 10.7.3-ce.0 though.
Is it possible to find out the pulled tag/version?
I already tried to use docker inspect gitlab/gitlab-ce, but the only information I could find was RepoTags pointing to gitlab/gitlab-ce:latest. Though there doesn't seem to be a specific version.

Resources