3. About docker file creation commands and first dockerfile creation

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Docker file creation process:

 FROM :
 This is 1st cmd in docker file creation used to mention about the OS related info.
 Tag is used to mention the version of the OS
 Syntax:
FROM ubuntu or FROM ubuntu:latest

 MAINTAINER:
 In this we can mention the maintainer name who is creating and maintain the docker
file
 Synatx:
MAINTAINER Santosh Pingali

 RUN :
 Run is the cmd used to mentioned parameters in run has executed during the
building of docker image
 Syntax:
RUN apt-get update&&apt-get install git

 CMD:
 Cmd is the cmd to use after the image has created and in the cmd which mentioned
parameters are executed as a pre-request to run the app
 Syntax:
CMD python /app/app.py

 LABLE:
 Lable is a metadata about the image like name email etc.
 Syntax:
LABLE name =”santosh”
LABLE email=santosh@abc.com
 EXPOSE:
 Expose is mostly used to enter the port details which app should consume to publish
to the outside world.
 Syntax:
EXPOSE 1234

Note:
i) you should open the port 1st after then use expose to publish the port for
your app.
ii) expose port doesn’t open automatically.

 ENV:
 Env deals with meta data about for which env you are going to create the image
 Env is key value pair
 Syntax:
ENV name QA

 ADD:
 Copy the content from source to destination and it also fetch the data from remote
URL etc
 Syntax:
ADD /home/spingali/jdk-1.8.1.tar.gz /usr/local

 COPY:
 Copy the content from source to destination without any fetching
Syntax: COPY /home/spingali/jdk-1.8.1.tar.gz /tmp

 ENTRYPOINT:
 instruction to provide executables that will always execute when the container is
launched.
 Syntax: ENTRYPOINT [“echo”, “Hello,santosh”]

 VOLUME:
 Deals about the mount volume
 Syntax: VOLUME [ /usr/lib/santosh]

Note: to check the volumes we can use cmd: docker volumes ls


 USER:
 Deals about the user details to run the docker fille
 Syntax: USER Santosh

 WORKDIR:
 Set the path to work dir so that cmds will starts executed based on workdir
 Syntax: WORKDIR /home

 SHELL:
 run commands and interact with the container's operating system and file system
 Syntax: SHELL ["/bin/bash", "-c"]

 STOPSIGNAL:
 If we can to send any signal to kernal to stop process while image building goes in
wrong direction.
 Syntax: STOPSIGNAL 9

 HEALTHCHECK:
 To check the health of the container we required the healthcheck cmd
 Mainly if we are monitoring the PROD containers it is very useful
 Syntax:
HEALTHCHECK CMD curl –fail <URL> || exit 1

Some important options in HEALTHCHECK is

 Interval - specifies the time between the health check for the application container. it
waits for the specified time from one check to another.
interval - DURATION (default: 30s)

 Timeout - specifies the time that the health check waits for a response to consider
the status of the container.
For example, if we define 30 seconds and our server doesn’t respond within 30
seconds, then it’s considered as failed.
timeout - DURATION (default: 30s)

 Start-period - specifies the number of seconds the container needs to start; health
check will wait for that time to start.
start-period - DURATION (default: 0s)
 Retries - specifies the number of consecutive health check failures required to
declare the container status as unhealthy.
Health check will only try up to the specified retry number. If the server fails
consecutively up to the specified times, it is then considered unhealthy.
retries - DURATION (default: 3)

My first docker file

As a pre-request login to docker using cmd : docker login

s-1: Vi Dockerfile

s-2: paste the below content

FROM ubuntu:latest

# Set the working directory in the image


WORKDIR /app

# Copy the files from the host file system to the image file system
COPY . /app

# Install the necessary packages


RUN apt-get update && apt-get install -y python3 python3-pip

# Set environment variables


ENV NAME World

# Run a command to start the application


CMD ["python3", "app.py"]

s-3: build the docker image using


docker build -t spingali1510/my-first-docker-image:latest .

T means Tag
s: 4 check the image is created or not using cmd: docker images

S-5 : run the container using below cmd


docker run -it spingali1510/my-first-docker-image

I mean interactive mode


T means terminal

You might also like