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.
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.
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.
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.
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.
Your understanding is correct when building from another image, with a few exceptions:
scratch
no image will be pulled. More information here.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 push
ed the image somewhere you won't be able to directly docker pull
the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With