A Docker image contains the code used to create a Docker container, such as creating a Nginx web server, or a mySQL server, or a home grown app, and the list goes on. In this way, an image is like a template used to create a container. An image is kind of like a virtual machine, but much more light weight, using significantly less storage a memory (containers are usually megabytes in size).
There are various ways to pull down an image:
- Using the docker pull command (as-is image as-is is pulled down)
- Using the docker run command (as-is image is pulled down and container is created/started)
- Using the docker build command (image can be customized)
- Using the docker stack deploy command (Docker Compose)
Before pulling down an image, you'll want to use the docker images command to return the list of images that have allready been pulled down, like this.
~]# sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE foo latest 105b54dc64f1 32 hours ago 196.7 MB
Then, use the docker search command to find the image you want to pull down.
The docker pull command followed by the name of the image pulls down the image. In this example, the "bar" image will be pulled down.
sudo docker pull bar
By default, the latest version of the image will be pulled down. Or, you can explicity include latest.
sudo docker pull bar:latest
Or you can specify a version.
sudo docker pull bar:0.1.2
And you can optionally specify the registry that contains the image.
sudo docker pull registry.example.com/bar:0.1.2
Or, as a more practical example, here is how you could pull down the latest version of the uwsgi-nginx-flask image in the tiangolo repository.
sudo docker pull tiangolo/uwsgi-nginx-flask:latest
Something like this should be displayed.
Unable to find image 'bar:latest' locally Trying to pull repository docker.io/library/bar ... latest: Pulling from docker.io/library/bar xxxxxxxxxxxxxx: Pull complete xxxxxxxxxxxxxx: Pull complete xxxxxxxxxxxxxx: Pull complete Digest: sha256:xxxxxxxxxxxxxxxxxxxxxxx ...
Reissuing the docker images command should now show that the latest bar image has been pulled down.
~]# sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE foo latest 105b54dc64f1 32 hours ago 196.7 MB bar latest 95ga44bc5582 2 weeks ago 967 B