Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is Docker Pull command different from Docker Build command

The official documentation from Docker, says:

Docker build - "Build an image from a Dockerfile"

Docker pull - "Pull an image or a repository from a registry"

Following is a sample Dockerfile:

FROM php:7.1.8-apache

MAINTAINER XXXX

COPY . /srv/app
COPY docker/vhosts.conf /etc/apache2/sites-available/000-default.conf

WORKDIR /srv/app

RUN docker-php-ext-install mbstring pdo pdo_mysql \
    && chown -R www-data:www-data /srv/app

It appears that build command will first download the image from the Docker hub and then do the other stuff as mentioned in the docker file. Whereas Docker pull will just download the image from the repository. In a way, 'pull' is part of the 'build'. I am new to Docker , I need confirmation for my understanding or let me knpw if there is more to it.

like image 764
srigu Avatar asked Sep 20 '18 11:09

srigu


People also ask

What is difference between docker and docker 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.

What does pull command do in docker?

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 docker build -- pull?

docker pull is used to pull from docker hub. If you use docker build without a docker file it throws an error. When you specify --pull or :latest docker will try to download the newest version (if any) Basically, if you add --pull, it will try to pull the newest version each time it is run.

What is the difference between docker run and docker build?

docker build builds a new image from the source code. docker create creates a writeable container from the image and prepares it for running. docker run creates the container (same as docker create ) and runs it.


2 Answers

Your understanding is correct when building from another image, with a few exceptions:

  1. If you build from scratch no image will be pulled. More information here.
  2. If the image is already on your computer (from a previous pull, build)
like image 97
Mikael Kjær Avatar answered Sep 29 '22 11:09

Mikael Kjær


If you have a Dockerfile for an image, and that image is also already in some repository, docker pull will pull the binary copy of the image from the repository, whereas docker build will rebuild it from the Dockerfile.

A couple of cases will also automatically docker pull for you. If you docker run an image you don't have, it will be pulled; a Dockerfile FROM line will also pull a base image if it's not present.

In your case the Dockerfile is describing how to build a new image, starting from the php:7.1.8-apache image. You need that base image to build your custom image, and if you don't have it already it will be pulled for you. But what you get out is a different image from that PHP base image, and unless you've docker pushed the image somewhere you won't be able to directly docker pull the result.

like image 43
David Maze Avatar answered Sep 29 '22 13:09

David Maze