Dockerfile
The Dockerfile uses DSL (Domain Specific Language) and contains instructions for generating a Docker image. Dockerfile will define the processes to quickly produce an image. While creating your application, you should create a Dockerfile in order since the Docker daemon runs all of the instructions from top to bottom. To learn more about the dockerfile refer to this link.
Docker Instructions
Instruction | Description |
---|---|
FROM | Identifies the base image that will be used to create the new image. |
COPY | Inserts data into the image from the host computer. |
ADD | Like COPY, but with the capacity to extract tarballs and access files from URLs. |
RUN | Continues out instructions within the image as it is currently being created. |
WORKDIR | Defines the working directory for additional instructions inside the image. |
CMD | Provides the default command that is going to be performed when the image-based container is started. |
ENTRYPOINT | Comparable to CMD, but with an executable provided for when the container starts. |
EXPOSE | Opens up a container’s specified ports for external service communication. |
ENV | Sets the image’s internal setting variables. |
VOLUME | Creates a volume or mount point for saving data between container runs. |
USER | Provides the user or UID that will be used to operate the container. |
LABEL | Adds key-value formatted metadata to the image. |
ARG | Defines variables to be provided to the Dockerfile during the build process at build time. |
ONBUILD | Provides a command to be run when the image is used as the foundation for another build. |
HEALTHCHECK | Provides a command for analyzing a container’s health. |
MAINTAINER | Indicates the Dockerfile’s author or maintainer. |
Creating a Dockerfile
You may create the Docker file on Linux by running the following command. The command to generate the Docker file is as follows. Only an empty file will be created as a result; we will then need to write the Docker instructions.
touch Dockerfile
Dockerignore
The .dockerignore
file is used to specify which files and directories Docker should ignore when building an image. It works similarly to .gitignore
in Git.
- Create a file named
.dockerignore
in the root directory of your Docker project. - List the files and directories you want Docker to ignore, one per line. You can use wildcards like
*
and!
to include or exclude specific files. - For example, if you want to ignore all files with
.log
extension and thenode_modules
directory, your.dockerignore
file might look like this:
*.log
node_modules
What is Docker Build ?
Docker is a tool that is used to create, deploy, and run applications using containers. Docker building files is also known as Dockerfiles. These are text files that contain instructions for building Docker images. In this article, we will explore the concept of Docker building files and steps to create a docker building files.