How to reconnect to default docker engine - docker

I have installed docker on my Windows 10, then I've created some images.
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 2cb0d9787c4d 3 weeks ago 1.85kB
Then I created my first machine using docker-machine create connected to hyperv driver.
so when I do docker images I get:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
My question is how can I reconnect to the default docker engine so if I run docker images I get:
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 2cb0d9787c4d 3 weeks ago 1.85kB

try image instead of images
docker image list
There seems to be some inconsistency w.r.t the two i.e. image/images. Though one would expect the output to be same but there are few differences.

Related

Pulling from repository

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

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

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>

how force deleting docker image affects existing containers using it

When i try to delete an image via docker rmi that has an existing container, i get an error message. ( normal )
When i add force flag docker rmi -f the image is deleted and when i check containers state using docker ps -athe container is still there but image namebecomes an ID.
So my question, from where comes this ID ? Is it a copy of the image that is kept in the cache and used for existing containers cause when i check docker images i find an image with in repo and in name and its ID is the one that is newly affected to old existing containers.
Another question that follows :
Once a container is created, is changing anything on the existing ( local ) image affecting in any way the existing containers ?
Thanks.
A docker image has a name and an image ID. This blog describes where the image ID is comming from in pre-docker-v1.10 and after it.
If you perform docker rmi -f image of an image which is used by a running container you're actually not deleting the real image but deleting the name and tag on the image.
So indeed docker ps will show:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
578e28246977 96931e4c66bd "/bin/tini -- /usr/lo" 3 minutes ago Up 3 minutes 8080/tcp, 50000/tcp drunk_shannon
But docker images is still showing your image:
<none> <none> 96931e4c66bd 6 weeks ago 711.9 MB
It's just untagged. The image isn't also deleted after you delete this container. The image remains in the list. You can start new containers from it with docker run -d 96931e4c66bd (by using the ID)
You can even retag it:
docker tag 96931e4c66bd my-jenkins:1.0
Than docker images shows:
my-jenkins 1.0 96931e4c66bd 6 weeks ago 711.9 MB
Another question that follows : Once a container is created, is
changing anything on the existing ( local ) image affecting in any way
the existing containers ?
No, when you make an "update" on your image (same name), the running container will probably lose it's image-name (only has an ID, just like when you're deleting your image during the container is running).
You'll need to reexecute the run-command with the new image (which will have another image-ID after the update) to have a container running from the newest image.

What is the difference between docker images and docker search commands?

On a coreOS (899.15.0) machine, when I execute docker search and images I get the following results :
docker search private-registry:5000/
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker images on the private registry machine:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
nginx latest e32087da8ee6dfa45221c48670fa9475f3d8a53a0e9ccabef4f741c62c77d49b 2 weeks ago 182.6 MB
registry 0.9.1 facc02b3acf6f811e8eace6d07b34cd5ab687e926ac5b5231da93264b259f1a4 12 weeks ago 422.8 MB
<none> <none> db81ebdc7ebd3d7aec05d4faa6f4c9c2e35954896e968bce2f90a9736485aa06 3 months ago 422.8 MB
...and a few more images
The reference for docker search mentions that it looks up on docker hub, but since I am specifying a specific registry here, I suppose it is looking up in the private repository.
I am not sure what is the difference between these two commands here and why the difference in results.
You are supposing wrongly. docker search searches only Docker Hub, not private registries. docker images command lists images on the machine (locally built or pulled from registries).
If you want to search or list images in the private registry, you need to use registry API to do so: https://docs.docker.com/registry/spec/api/

Resources