Docker: A primer for PHP Developers
A file called Dockerfile (no file extension) is a file which gives instructions to Docker on how to build a container image.
Dockerfiles typically start with the FROM command (also called instruction argument) followed by the name of the base
image.
Before we look at an example of a Dockerfile, we mention commands typically found in Dockerfiles.
We want to create a wget application using Dockerfile:
A wget application is used to download files.
When the URL of a webpage is entered, it downloads the full web page file.
(wget is installed by default in Linux but for Windows, we need to install it.)
Steps:
1. Set the base image
2. Pull the lightweight OS Alpine using apk, the package manager for Alpine
3. Remove apk cache
4. Set the working directory
5. Remove apk cache
6. Define the entry point
7. Define the CMD command (optional)
FROM alpine
LABEL VERSION=0.1 \
AUTHOR=KBARUT \
EMAIL=kamibarut@yahoo.com
RUN apk update \
&& apk add wget \
&& rm -rf /var/cache/apk/*
WORKDIR /root/
ENTRYPOINT [ "get" ]
CMD [ "--help" ]
The next step is to build this image from the Dockerfile using the following generic command:
$ docker build -t [username/]< image-name >[:tag] < dockerfile-path >
In our case:
$ docker build -t kbarut/app:latest -f docker/app/Dockerfile docker/app