It is a text file that consists of a set of instructions/sets of tasks.
It is used for automation which saves time.
You can't do changes in images but you can do modifications in the docker file and create a new image.
Docker Components :
FROM :
It is the topmost field of the file.
It states the base image of the container.
e.g. FROM ubuntuRUN :
It executes the commands.
As we add the commands, it creates the layer of the image.
e.g. RUN echo "Hello Pranav" > /tmp/test.txtCOPY :
It is used for copying the files from the local machine.
You can't use remote files for copying.
e.g. COPY <source> <destination>ADD :
It is similar to COPY, but it provides a feature to download files from a remote location.
It is also used for extracting the archive files.
e.g. ADD <source> <destination>EXPOSE :
It exposes the port to the docker.
It decides which port should be open for that container.
e.g. EXPOSE 8080WORKDIR :
The WORKDIR command is used to define the working directory of a Docker container at any given time.
e.g WORKDIR /varCMD :
It sets the default parameters which are overridden by the Docker Command Line Interface (CLI) when a container is running.
e.g. CMD yum install httpd -yENTRYPOINT
Default parameters that cannot be overridden when Docker Containers run with CLI parameters.
e.g. ENTRYPOINT yum update -yVOLUME
It is a directory somewhere in your Docker storage directory and can be mounted to one or many containers.
e.g. VOLUME /var/log/appENV
For declaring the environmental variable we use "ENV".
e.g. ENV myname=PranavARG
It is used for providing arguments to the commands.
You can use this as a Parameter and Default Value for it.
e.g. ARG Default_Passing_MarksUSER
The USER command sets the startup user ID or user name in the new image.
e.g. USER <UserId>
e.g. USER <UserName>MAINTAINER
This will notify the owner of the file i.e Who has written the Docker File.
MAINTAINER <email-id>
Docker File Example
#This is a sample Image
FROM ubuntu
MAINTAINER mytestmail@gmail.com
RUN apt-get update
RUN apt-get install –y nginx
CMD [“echo”,”Image created”]
#This is a sample Image
FROM ubuntu
MAINTAINER mytestmail@gmail.com
ENV Home_Dir=/root/
COPY /var/log/test.log /tmp
WORKDIR /var
ADD /var/log/all_log.tar.gz /tmp
#This is a sample Image
FROM ubuntu
MAINTAINER mytestmail@gmail.com
VOLUME /var/log
EXPOSE 8080
USER docker_user
ENTRYPOINT yum update -y
Note:
Special thanks to Pranoti Parkale & Ritik Khode for their help.