Pulling from repository - docker

I just created an image :
docker build firstimage .
and tagged it as sohrabp72/firstimage and then pushed it into my repo on the Docker hub:
docker tag firstimage sohrabp72/firstimage
Then I removed the tagged image and the original image from my local machine:
docker rmi sohrabp72/firstimage
docker rmi firstimage
Now when I want to pull the image from the Docker hub repository, my local Docker does not pull it:
C:\Users\Sohrab> docker pull sohrabp72/firstimage
Using default tag: latest
latest: Pulling from sohrabp72/firstimage
cbdbe7a5bc2a: Already exists
9287919c3a0f: Already exists
43a47bbd54c9: Already exists
3c1bcea295c4: Already exists
53e2ab46e733: Already exists
3b08dc288a15: Already exists
e01ad7774a4c: Already exists
Digest: sha256:f16f1cfd9e777898511259e7ff512947c27b7e7bb4f4333dd27bd809bdc77995
Status: Downloaded newer image for sohrabp72/firstimage:latest
docker.io/sohrabp72/firstimage:latest
PS C:\Users\Sohrab>
docker logs show some lines and say already exist. and when I look at images on my local docker, that image is there:
C:\Users\Sohrab> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
getting-started latest bfc5750a86e5 11 hours ago 231MB
sohrabp72/firstimage latest 4e197282638a 22 hours ago 179MB
node 12-alpine d8b74300d554 7 days ago 89.6MB
docker/getting-started latest 1f32459ef038 3 months ago 26.8MB
Is there something like a cache for images we've pushed to Docker hub?

When docker prepares an image, it does step by step and each step creates an intermediate step with an ID. Docker by default removes the intermediate image and the last step provides a final image with an ID.
When you ran build command it actually created a final image with an ID and tagged the final image ID with your name 'firstimage'
When you tag second name, it added additional tag 'sohrabp72/firstimage'
When you ran docker rmi command on both tags, it removed tags only while image created still is there.
You can run
docker images -a
which will list image with <<"none">> in repository and name but final image created will be there with ID
you can
docker image prune -a
to clear all image and try docker pull command

Related

Docker Registry: Newly tagged image can be found, but not found when pulled

Using :latest image as a base, I have created a new image tagged with :v1.1.0-fermium. After tagging, the newly tagged image :v1.1.0-fermium appears within registry listing of docker images, including :latest
Problem: The :latest image can be pulled from registry, but not the newly tagged :v1.1.0-fermium image, not found registry.
Question: Is there a step I am missing when tagging a docker image in order to be found when pulling from a docker registry?
$ docker image tag docker.foo.com/bar-build:latest docker.foo.com/bar-build:v1.1.0-fermium
$ docker image ls docker.foo.com/bar-build
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.foo.com/bar-build latest 35bfeb2c6323 5 hours ago 5.03GB
docker.foo.com/bar-build v1.1.0-fermium 35bfeb2c6323 5 hours ago 5.03GB
$ docker pull docker.foo.com/bar-build:latest
latest: Pulling from bar-build
$ docker pull docker.foo.com/bar-build:v1.1.0-fermium
Error response from daemon: manifest for docker.foo.com/bar-build:v1.1.0-fermium not found: manifest unknown: The named manifest is not known to the registry.
Kindly Push the docker image into hub.docker.com for publishing it and then you can pull the image.

Docker pull: still having old image after pull

I noticed that the docker image I'm using is older than the one on dockerhub. Running docker pull seems to work, but later when running docker images I still see the old image, even if I first explicitly removed it with docker rmi.
Output of docker pull:
# docker pull staltz/ssb-room
Using default tag: latest
latest: Pulling from staltz/ssb-room
9a0b0ce99936: Already exists
db3b6004c61a: Already exists
f8f075920295: Already exists
6ef14aff1139: Already exists
0bbd8b48260f: Pull complete
524be717efb1: Pull complete
aad1e8812bc2: Pull complete
13fb072986db: Pull complete
627a2df19018: Pull complete
fb8dcb3732a4: Pull complete
2bc41d47dd50: Pull complete
058f4db9be8e: Pull complete
8f21c57f425d: Pull complete
Digest: sha256:a7c49c796823312f8c1d155eb636bbd974bc55036c2180f16f17d3340fcebbe7
Status: Downloaded newer image for staltz/ssb-room:latest
docker.io/staltz/ssb-room:latest
Output of docker images:
# docker images staltz/ssb-room
REPOSITORY TAG IMAGE ID CREATED SIZE
staltz/ssb-room latest 6097b401900c 4 months ago 930MB
Why is it again showing that 4-months old image?

Rename Docker repository

I need to change the name of the Docker repository. For example...
ORIGINAL:
[root#docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.access.redhat.com/rhel7/rhel latest e64297b706b7 2 weeks ago 201MB
RENAMED:
[root#docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rhel 7.5 e64297b706b7 2 weeks ago 201MB
You do not 'rename' images. What you see in docker images are tags. You can add a new tag or delete one, but not 'rename'. Try tagging your image with the new tag that you want and then (optionally), delete the old tag, e.g.:
docker tag registry.access.redhat.com/rhel7/rhel:latest rhel:7.5
docker rmi registry.access.redhat.com/rhel7/rhel:latest # remove old tag

Docker save/load lose original image repository/name/tag

I'm using Docker 1.12.6.
I have pulled an image from the Docker registry.
I have exported the images as tar files using the docker save command.
I removed the original image and container and loaded the exported image using docker load -i myImage.tar.
Now, when running docker images I notice my image have lost its repository/tag information:
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 5fae4d4b9e02 8 weeks ago 581.3 MB
Why does it have this behavior and how do I keep the original image name?
Use
docker save -o filename.tar <repo>:<tag>
The command docker save <image id> removes the repository and tag names.
To solve this, use docker save <repo>:<tag> it will keep the repository and tag name in the saved file. For example:
docker save -o ubutu-18.04.tar ubuntu:18.04
I had the same problem, so I used the following command to fix it manually:
docker tag <Image-ID> <desired Name:Tag>
Reference
[NOTE]:
It's inconsistent: docker save image-repo-name -> docker load
restores name, docker save SHA -> docker load no names or tags,
docker save name:latest -> docker load no names or tags.
AND:
The current (and correct) behavior is as follows:
docker save repo
Saves all tagged images + parents in the repo, and creates a
repositories file listing the tags
docker save repo:tag
Saves tagged image + parents in repo, and creates a repositories file
listing the tag
docker save imageid
Saves image + parents, does not create repositories file. The save
relates to the image only, and tags are left out by design and left as
an exercise for the user to populate based on their own naming
convention.
Reference
A single image ID can have multiple names/tags,
so the way that you loose the the names and tags is
what I would expect to happen after saving and loading the image to/from a tar ball.
Mode details are in the discussion about it here
From docker documentation:
cat exampleimage.tgz | docker import - exampleimagelocal:new
root#mymachine:/tmp# cat myimage.tar | docker import --message "New image imported from tarball" - reponame:my-image-name
sha256:be0794427222dcb81182a59c4664b350ecb5ffb7b37928d52d72b31
root#mymachine:/tmp# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
reponame my-image-name be0794427222 6 seconds ago 4.31GB
This one worked for me.
This is a work around
Go to source docker host machine, create text file containing all the image details using the following command docker image ls > images.txt
The above command will produce a text file similar to the following
REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 293e4ed402ba 2 weeks ago 315MB <none> <none> d8e4b0afd6ba 2 weeks ago 551MB
Make necessary edits to set the tag by using docker image tag command
docker image tag 293e4ed402ba postgres:latest
docker image tag d8e4b0afd6ba wordpress:latest
I wrote a one-line script that importing a bunch of .tar files and immediately tagging the image.
for image in $(ls); do docker tag "$(echo $(docker import $image))" $image ; done
Note, that you should be inside the folder when all the tar files are located.

how to get the layers of a docker image on local host

Just started playing with docker on Ubuntu. I pulled a docker image as follows.
docker pull coreos/apache
Now I see there there three layers being pulled.
Using default tag: latest
latest: Pulling from coreos/apache
a3ed95caeb02: Pull complete
5e160ca0bb5a: Pull complete
1f92e2761bfd: Pull complete
Digest: sha256:9af520cee7bedcda564970ff790cdf2e72b6daccce8539f6b3c880ed7fc21091
Status: Downloaded newer image for coreos/apache:latest
From the above, I see that there are three layers for this image.
But now, lets say I close and reopen the terminal, how can I get the layers(same info above) of this image. What is the command?
When I do docker images I get this.
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 0584b3d2cf6d 9 days ago 196.5 MB
hello-world latest c54a2cc56cbb 4 months ago 1.848 kB
coreos/apache latest 5a3024d885c8 2 years ago 294.4 MB
Now that I know the image id, how can I get the layers for that image id.
The tree option as in
docker images --tree
is not working anymore. It seems to be removed. If not one command how can I get that using a sequence of command at least.
If you have the busybox, here is how I would get it.
docker inspect busybox - would show long configuration in json format and below is the excerpt from it to get the layers.
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:e88b3f82283bc59d5e0df427c824e9f95557e661fcb0ea15fb0fb6f97760f9d9"
]
}
You can simple filter it by below command using --format option of docker inspect which would give exactly what OP is looking for.
rao # ubuntu $ docker inspect --format '{{.RootFS.Layers}}' busybox
[sha256:e88b3f82283bc59d5e0df427c824e9f95557e661fcb0ea15fb0fb6f97760f9d9]
now that the image has been downloaded to your local host (in layers), even if you kill your terminal and log back in, the image will still exist on your host. it's downloaded in layers, but resides as an image on your localhost that you can now instantiate into a container using 'docker run'
if you want to pull the image down again and see all the layers being pulled, you can first erase your image (docker rmi ), then do your 'docker pull coreos/apache' again. HTH
edit: to show actual layers that went into an image, run:
docker history <imageid>

Resources