Dockerfile is a script configuration that contains all the commands that a user can call on the command line to assemble an image. as well the Dockerfile is essentially the build instructions to build the image. You can use docker build to make an automated build to execute several command-line guidelines n progression
The docker build command builds an image from a Dockerfile and a context. The build’s context is the set of files at a specified location PATH or URL. The PATH is a directory on your local file system. The URL is a Git repository location.
Dockerfile Environment variable:
LABEL – Instruction adds metadata to an image. A LABEL is a key-value pair.
|ENTRYPOINT – should be defined when using the container as an executable|
|ARG – that users can pass at build-time to the builder with the docker build(passing secrets like GitHub keys, user credentials, etc.)|
|WORKDIR – The working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.|
|ONBUILD – The image a trigger instruction to be executed at a later time when the image is used as the base for another build.|
|RUN – execute any commands in a new layer on top of the current image and commit the results.|
| FROM – Instruction initializes a new build stage and sets the Base Image for subsequent|
| ADD – Copies new files, directories, or remote file URLs from “src” and adds them to the filesystem of the image at the path “Dest”.|
|COPY – Copies new files or directories from “src” and adds them to the filesystem of the container at the path “Dest”.|
|ENV – All subsequent instructions in the build stage and can be replaced inline in many as well.|
|EXPOSE – listens on the specified network ports listens on TCP or UDP protocol|
|STOPSIGNAL – The system call signal that will be sent to the container to exit|
|USER – The user name (or UID) and optionally the user group (or GID) to use when running the image and for any RUN, CMD and ENTRYPOINT|
|VOLUME – creates a mount point with the specified name and marks it as holding externally mounted volumes from the native host or other containers.|
Create a Dockerfile
The most widely scenario while making Docker images is to pull a current image from a registry (ordinarily from Docker Hub) and indicate the changes you need to make on the base image. The most regularly utilized base image while creating Docker image is Alpine on the grounds that it is little and optimized run in RAM.
Below you can see some examples of Dockerfile
FROM ubuntu:21.04 ENV LANG C.UTF-8 MAINTAINER Linux RUN apt-get update && apt-get install -y apache2 COPY test.html /var/www/html/ RUN chown -R www-data:www-data /var/www/html ENV APACHE_DOCUMENT_ROOT=/var/www/html/index.php RUN chmod 0644 /etc/cron.d/ad-cron EXPOSE 80 443 ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
In this blog describe how to create a Dockerfile, explain about Environment variable and example of creating the Dockerfile