DevOps Classroomnotes 03/Feb/2022

Containerizing Applications (Building Docker Images)

  • To build the Docker Images, we will be using the Dockerfile approach
  • Refer Here for the official docs of Dockerfile
  • In Dockerfile we use instructions mentioned in the above reference.
  • The basic instructions are
  • FROM => Helps in choosing the base image
  • RUN => Adds the execution/installation on the base image to build our application
  • LABEL => ADDS metadata
  • ENV => Set ENVIRONMENT variables
  • EXPOSE => PORTS to be exposed by application
  • ADD/COPY => Content to be added into the image from local or from urlss
  • USER => User with which container has to be started (if not specificed root)
  • WORKDIR => Working Directory
  • ARG => Build time arguments
  • CMD => Command that will be called when container is created
  • ENTRYPOINT => Command that will be called when container is created
  • Activity 3: Lets create a image for an Spring boot based application (Java Spring boot):
  • Manually running the application:
    • Ensure java is installed (Java 8 or Java 11)
    • Download the jar file of your application
    • Find the port on which your application runs
    • EXECUTE the following command to start application java -jar <app.jar>
  • For the Spring Petclinic Sample app Refer Here
  • This application runs on java 11. The port it exposes is 8080
  • Manual Steps:
    sudo apt update
    sudo apt install openjdk-11-jdk -y
    java -jar spring-petclinic-2.4.2.jar
  • Now to choose a base image we would prefer a base image with JAVA 11 installed.
  • Refer Here for the Dockerfile created.
  • Now create a image using Docker image build
  • Now lets look at images
  • Now lets try to create the container using spc:1.0 docker container run -d --name myspc1 -P spc:1.0
  • Lets see if we can this better, we can use the slim version of the open jdk which gives the exact same result i.e. our application will be working from a docker image of much less size. Refer Here

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner