What is the difference between docker run and docker pull - docker

I am new to Docker. Can anyone help me in understanding the difference between
docker run img_name & docker pull img_name?
Do they work the same?

docker pull pulls an image or a repository from a registry.
docker run runs a command in a new container.
They don't work the same, however, if you use docker run with an image that you haven't pulled yet, docker run will call docker pull:
$ docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world#sha256:6f744a2005b12a704d2608d8070a494ad1145636eeb74a570c56b94d94ccdbfc
Deleted: sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e
Deleted: sha256:af0b15c8625bb1938f1d7b17081031f649fd14e6b233688eea3c5483994a66a3
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:6f744a2005b12a704d2608d8070a494ad1145636eeb74a570c56b94d94ccdbfc
Status: Downloaded newer image for hello-world:latest
…
Please see docker help pull and docker help run for more information.

Related

Cannot run docker:dind as docker:docker

I cannot run docker:dind as docker:docker even I intuitively should:
[sad#localhost ~]$ docker pull docker
Using default tag: latest
latest: Pulling from library/docker
540db60ca938: Already exists
5a38b3726f4b: Already exists
e5fa5deb3340: Already exists
2b7e0e3b7545: Already exists
493333e9491f: Already exists
28d445cfca76: Already exists
32eb6dfb9227: Already exists
Digest: sha256:ad50b8d78b41dc52f42ab123ce0e3f48c54437ed70ecc2a44c99e889924c8e56
Status: Downloaded newer image for docker:latest
docker.io/library/docker:latest
[sad#localhost ~]$ docker run --privileged -d docker:docker
Unable to find image 'docker:docker' locally
docker: Error response from daemon: manifest for docker:docker not found: manifest unknown: manifest unknown.
See 'docker run --help'.
[sad#localhost ~]$
Is this by design, that I should reference the docker:docker image as docker:dind?
Thank you.
You have to change
docker run --privileged -d docker:docker
into
docker run --privileged -d docker:latest

Docker run does not display any output

I installed docker on a raspberry-pi (Connected via ssh)
Installation is successful.
But running docker run hello-world produce no output.
Note on very first time I got additional messages regard installing image
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ad0f38092cf2: Pull complete
Digest: sha256:e366bc07db5e8a50dbabadd94c2a95d212bc103e3557e47df8a2eebd8bb46309
Status: Downloaded newer image for hello-world:latest
But there is no actual output from hello world script
Note I installed docker using command curl -sSL https://get.docker.com | sh
I tried following command too
sudo usermod -aG docker pi
sudo systemctl start docker
sudo docker run hello-world
Tried following commands docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
734dd8f733d7 hello-world "/hello" About a minute ago Exited (139) 59 seconds ago thirsty_bhaskara
I ran into the same issue on a Raspberry Pi 1B+ (armv6l). Inspired by #JanDrábek's answer, the first observation is that the hello-world image would indeed be one supporting ARM, yet only after using hypriot/armhf-hello-world instead did I get the expected output:
$ uname -a
Linux 4.1.19+ #858 Tue Mar 15 15:52:03 GMT 2016 armv6l GNU/Linux
$ docker run hello-world # No output
$ docker image inspect hello-world | grep Architecture # Arch looks right though
"Architecture": "arm",
$ docker run hypriot/armhf-hello-world # This does the job
Hello from Docker.
This message shows that your installation appears to be working correctly.
run:
docker ps -a
and check if you can see the exited container.
take the container ID from the output and type
docker logs <ID>
this will allow you to see the logs.
if you want to see the output in the first place when you run it add -it flags to the run command
edit:
I tried in on my machine:
docker run -it hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:e366bc07db5e8a50dbabadd94c2a95d212bc103e3557e47df8a2eebd8bb46309
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
maybe your output is redirected to some other stream.
try using :
docker run -it hello-world > ./test.txt 2>&1
after that check if the file has any content
I was having similar issue, my solution was definitely very naive but I basically removed all container and images and then tried again. It worked.
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
I recently had same problem on my freshly installed Fedora 28 (up-to-date)... the containers all exited with exit code 139, the docker events said that it died, and docker logs said nothing.
My solution was to update the docker (or switch to CE edition) as the installed docker version was 1.13 which is quite old. (The tutorial for fedora https://docs.docker.com/install/linux/docker-ce/fedora/)
Also I have came across one potential thing to check... is your container compatible with your architecture (raspberry is ARM isn't it?) Use docker image inspect <image> search for Architecture.

pull and push docker image to localhost via dind

When build images in dind (docker in docker), the image is only accessible in dind.
$ docker run -d --name dind --privileged --net=host -v `pwd`:/app -w /app docker:stable-dind
fe66d6e7e5effcf15e439a332a2368fddab810e9bc8ac3445392c8e56b0aa38a
$ docker exec dind ls
Dockerfile
$ docker exec dind docker build -t demo .
Sending build context to Docker daemon 521.7kB
Step 1/24 : FROM alpine
...
$ docker exec dind docker images|grep demo
REPOSITORY TAG IMAGE ID CREATED SIZE
demo latest a9dd4e725029 7 seconds ago 88.3MB
$ docker images |grep demo
<no result>
I can push the image to public or private docker registry server in dind, because they have IP or dns name to access. But how can I push the new image back to localhost (the host running dind)
Second, if I want to pull image from localhost in Dind, how to do that?
I can answer my first question now.
$ docker exec dind docker save demo |docker load
2f7d711abbe9: Loading layer [==================================================>] 11.44MB/11.44MB
...
Loaded image: demo:latest
$ docker images |grep demo
demo latest a9dd4e725029 8 minutes ago 88.3MB
Same size :-)
But still not sure how to pull image from localhost in Dind, any ideas?

docker missing var/lib/docker folder

I was trying to do something, but I have accidentally deleted docker folder at var/lib/docker, and now I can not install another docker any more. What to do now? How can I fix this problem and install new docker.
sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pulling fs layer
docker: open /var/lib/docker/tmp/GetImageBlob974250330: no such file or directory.
See 'docker run --help'.
have you tried to simply restart docker this way?
systemctl restart docker
or
sudo service docker stop
sudo service docker start

Unable to pull my private image from docker hub

After I upgrade my docker from 1.8.2-el7 to version 1.12.6, its failing to pull my private images from docker hub.
I could able to perform the list image command
sudo docker -H tcp://test-app01.local:2376 images
REPOSITORY TAG IMAGE ID CREATED SIZE
account/image1 tag1 a4c286f0ec9e 10 hours ago 864.7 MB
ubuntu latest d355ed3537e9 8 days ago 119.2 MB
account/image1 tag2 4abd8c3ed720 3 months ago 878.8 MB
But it's unable to pull latest image from repo with successful login.
sudo docker -H tcp://test-app01.local:2376 login -u username -p password
Login Succeeded
sudo docker -H tcp://test-app01.local:2376 pull account/image1:tag1
Using default tag: tag1
Pulling repository docker.io/account/image1
Error: image account/image1:latest not found
Can somebody please assist to fix this issue.
As you can see in the image command, you have only tag1 and tag2 image tags.
If you don't specify any, docker will look for latest which you don't have. So pull as this for tag1:
sudo docker -H tcp://test-app01.local:2376 pull account/image1:tag1
Or this for tag2:
sudo docker -H tcp://test-app01.local:2376 pull account/image1:tag2

Resources