Docker - For Beginner Part 4

Docker - For Beginner Part 4

Docker file

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 :

  1. FROM :
    It is the topmost field of the file.
    It states the base image of the container.
    e.g. FROM ubuntu

  2. RUN :
    It executes the commands.
    As we add the commands, it creates the layer of the image.
    e.g. RUN echo "Hello Pranav" > /tmp/test.txt

  3. COPY :
    It is used for copying the files from the local machine.
    You can't use remote files for copying.
    e.g. COPY <source> <destination>

  4. 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>

  5. EXPOSE :
    It exposes the port to the docker.
    It decides which port should be open for that container.
    e.g. EXPOSE 8080

  6. WORKDIR :
    The WORKDIR command is used to define the working directory of a Docker container at any given time.
    e.g WORKDIR /var

  7. CMD :
    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 -y

  8. ENTRYPOINT
    Default parameters that cannot be overridden when Docker Containers run with CLI parameters.
    e.g. ENTRYPOINT yum update -y

  9. VOLUME
    It is a directory somewhere in your Docker storage directory and can be mounted to one or many containers.
    e.g. VOLUME /var/log/app

  10. ENV
    For declaring the environmental variable we use "ENV".
    e.g. ENV myname=Pranav

  11. ARG
    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_Marks

  12. USER
    The USER command sets the startup user ID or user name in the new image.
    e.g. USER <UserId>
    e.g. USER <UserName>

  13. 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.