Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker run vs pull

Tags:

docker

ubuntu

I am a beginner in docker and referring this to install and understand basics but I am little confused about run and pull command.

What is the difference between docker run and docker pull commands for Docker images?

like image 418
Alien Avatar asked May 01 '19 19:05

Alien


People also ask

What is the difference between docker run and docker pull?

docker pull pulls an image or a repository from a registry. docker run runs a command in a new container.

Does docker run do pull?

The docker pull command downloads Docker images from the internet. The docker image command lists Docker images that are (now) on your computer. The docker run command creates running containers from images and can run commands inside them.

When should I use docker pull?

The 'docker pull' is a Docker command to download a Docker image or a repository locally on the host from a public or private registry. When we run any container and the specified Docker image is not present locally then it first pulls it from the registry.

What is purpose of of docker run?

Docker allows you to run a container in interactive mode. This means you can execute commands inside the container while it is still running.


3 Answers

docker run runs an instance of a container. In order to do that it will pull all the required images needed to run the container (i.e. base images) in the background if they are not part of the local cache.

docker pull will fetch/pull an image from the docker registry.

Think of it similar to git fetch and git pull if you have worked with git.
git pull will do git fetch (and git merge)

like image 57
Cratylus Avatar answered Oct 19 '22 18:10

Cratylus


From the docs:

docker run:

The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command. A stopped container can be restarted with all its previous changes intact using docker start. See docker ps -a to view a list of all containers.

If the image you are trying to run is not downloaded yet it will be automatically fetched with pull.

docker pull:

Most of your images will be created on top of a base image from the Docker Hub registry.

Docker Hub contains many pre-built images that you can pull and try without needing to define and configure your own.

To download a particular image, or set of images (i.e., a repository), use docker pull.

So docker pull will download or update an image.

like image 34
Samuel Philipp Avatar answered Oct 19 '22 19:10

Samuel Philipp


Pull will download new versions of images if there are any, while run will only download an image if you don't have a local copy.

like image 27
KnowledgeHunter Prits Avatar answered Oct 19 '22 18:10

KnowledgeHunter Prits