DevOps Classroom Series – 24/Aug/2021

Dockerfile Instructions and Image Creations

  • To create a docker container we need an image.

  • Applications will have different versions, To accomodate this in docker container images, Docker images have tags.

  • The syntactic name of docker image <image-name>:<tag-name>.

  • If we don’t pass the tag-name the default tag latest will be applied.

  • To create any Docker image, we need to know the manual steps for configuring and Running the application.

  • To make the process of creating docker images simple, Docker has `Dockerfile“ which is text file and contains instructions on how to build a container image.

  • This is declarative way of building images

  • Refer Here for the Dockerfile instructions and reference

  • Lets start with simple instructions

    • FROM:
      • Using this we define what is the base image for building our custom application image
      FROM <base-image>:<tag>
      
      • It is recommended not to use the latest tag prefer specific tags over here
      • If you really want to start to build a custom image with out any specific base image FROM scratch
      • Refer Here
    • LABEL: Adds metadata to the image Refer Here
    • ADD: This instruction can be used to copy the files from http or docker host into docker image
    ADD <source> <destination>
    
    • COPY: This instruction can be used to copy the files from docker host into docker image
    COPY <source> <destination>
    
    • RUN
    • EXPOSE: Expose instruction infor Docker that the container is listenting to the specific netowrk ports
    EXPOSE <port> [<port>/<protocol>]
    
    • CMD: This instruction executes the command when the container is created Refer Here
  • The Dockerfile for springpetclinic which we have created is

FROM openjdk:11
LABEL author="khaja ibrahim"
LABEL organization="quality thought"
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/spring-petclinic-2.4.2.jar /spring-petclinic.jar
EXPOSE 8080
CMD [ "java", "-jar", "/spring-petclinic.jar" ]

  • Now lets try to build a docker image
docker image build -t <image-name>:<tag> <path to folder where Dockerfile>

docker image build -t <image-name>:<tag> -f <path to Dockerfile>

Preview

  • We can alos use the slim versions from base image if available
FROM openjdk:11-slim
LABEL author="khaja ibrahim"
LABEL organization="quality thought"
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/spring-petclinic-2.4.2.jar /spring-petclinic.jar
EXPOSE 8080
CMD [ "java", "-jar", "/spring-petclinic.jar" ]

FROM tomcat:jdk8
LABEL author="khaja"
EXPOSE 8080
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/gameoflife.war /usr/local/tomcat/webapps/gameoflife.war

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube