About Docker File Creation Commands and First Dockerfile Creation
About Docker File Creation Commands and First Dockerfile Creation
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 protected]
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]
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
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)
s-1: Vi Dockerfile
FROM ubuntu:latest
# Copy the files from the host file system to the image file system
COPY . /app
T means Tag
s: 4 check the image is created or not using cmd: docker images