Working with Dockerfile
When assembling an image, whether by a Docker commit or export, optimizing the outcome in a managed way is a challenge, let alone integrating with a CI/CD pipeline. On the other hand, Dockerfile
represents the building task in the form of as-a-code, which significantly reduces the complexities of building a task for us. In this section, we will describe how to map Docker commands into a Dockerfile
and go a step further to optimizing it.
Writing your first Dockerfile
A Dockerfile
consists of a series of text instructions to guide the Docker daemon to form a Docker image. Generally, a Dockerfile
is and must be starting with the directive FROM
, and follows zero or more instructions. For example, we may have an image built from the following one liner:
docker commit $( \
docker start $( \
docker create alpine /bin/sh -c \
"echo My custom build > /etc/motd" \
))
It roughly equates to the following Dockerfile
:
./Dockerfile:
---
FROM alpine
RUN echo "My custom build...