Downloading Docker images
In this recipe, we will download a Docker image. In a production environment, while creating a Docker image for an application, we need to add code and the configurations of our application over the top of an existing Docker image (sometimes referred to as a base image), such as Ubuntu, CentOS, and so on. When we deploy a container to a critical environment, we want to minimize the risk of delays. Therefore, it is better to download the image locally before using the docker_container
module, so as to reduce the deployment time. In this recipe, we will also learn how to create a Docker image using Dockerfile.
How to do it…
- Let's define the task to pull a Docker image:
- name: Download docker image docker_image: name: ubuntu tags: - recipe3
- Let's now create a dummy project to build a Docker image:
# Let us create our project directory aside our playbook $ mkdir docker_files # Let us create our Dockerfile $ vim Dockerfile FROM ubuntu:latest CMD ["sleep"...