Saturday, 26 October 2019

Docker File


Introduction to Dockerfile:

Dockerfile is a text which can be used to automate the customization in containers.

FROM----ADD----RUN----CMD----ENTRYPOINT----ENV

FROM: this keyword is used to define the base image, on which we will be building. Eg: FROM Ubuntu

ADD: This keyword is used to add files to the container being built. Eg: ADD <source> <destination in container>    

      Ex: ADD . /var/www/html

COPY – copy the data from current working directory

WORKDIR: changing directory in the container

RUN: This keyword is used to run some operation. Eg: installation
              Ex: RUN yum –y install httpd

CMD: This keyword is used to run commands on the start of the container. These commands run only when there is no argument specified while running the container.

Eg: I want to start my apache service while starting container. So the command whatever we mentioned in CMD, those can be triggered during container start.

              CMD /etc/init.d/httpd start  --command running without arguments.

ENTRYPOINT: This keyword is used to run commands with arguments.

              ENTRYPOINT apachectl –D FOREGROUND

ENV: This keyword is used to add environment variables in container.

              ENV JAVA_HOME /var/java_home/

ONBUILD: this will be used in Parent Image docker file for rebuild and parent image can be used in child  
Dockerfile.

Build a dockerfile:

# docker build <path_of_dockerfile> -t <new_image_name> 

--this will create a new customized container for me.

Docker File:






No comments:

Post a Comment