DevOps Classroom notes 30/Jan/2025

Other Dockerfile Instructions

  • LABEL: It adds Metadata to the image
  • RUN
  • CMD
  • EXPOSE: This instructions adds information about the ports of the application
  • ARG
  • ENV
  • ENTRYPOINT
  • WORKDIR
  • USER: This sets the user to run inside the container. User has to be existing before using this instruction.

Points to consider

  • Container will be in running state as long as the command which was started when container is created is running
  • When we dont mention CMD/Entrypoint in Dockerfile based images CMD will be used.
  • When we dont expose ports and if base image has Expose by default those will the ports
  • While running the container we can statically forward ports by using -p <host-port>:<contianer-port>
docker run -p 80:8080 -d spc:1
docker run -p 8080:8080 -d spc:1
  • Docker gives a dynamic way to attach ports to container port by using -P
  • We can execute commands in running container using docker container exec

Sample Application – Java

  • This application is developed in spring boot
  • The jar file is available for download from here
  • Steps:
    • Install java 17 or above
    • download jar file wget https://referenceappslt.s3.ap-south-1.amazonaws.com/spring-petclinic-3.3.0-SNAPSHOT.jar
    • run the app java -jar spring-petclinic-3.3.0-SNAPSHOT.jar
  • Application runs on port 8080
  • Lets start containerizeing this application
FROM eclipse-temurin:17
LABEL project="learning" 
LABEL author="khaja"
ADD https://referenceappslt.s3.ap-south-1.amazonaws.com/spring-petclinic-3.3.0-SNAPSHOT.jar /spring-petclinic-3.3.0-SNAPSHOT.jar
EXPOSE 8080
# CMD Executes when the container is started
CMD [ "java", "-jar", "/spring-petclinic-3.3.0-SNAPSHOT.jar" ]
  • Refer Here for the changes done
  • Lets findout the user using which our application is getting started
  • Our application is also copied to root directory
  • Creating a directory for application Refer Here
  • Exercise: Image is created from the following Dockerfile. The contianer is not starting (exited state) Findout the reason
FROM eclipse-temurin:17
LABEL project="learning" 
LABEL author="khaja"
USER nobody
ADD https://referenceappslt.s3.ap-south-1.amazonaws.com/spring-petclinic-3.3.0-SNAPSHOT.jar /apps/spring-petclinic-3.3.0-SNAPSHOT.jar
EXPOSE 8080
# CMD Executes when the container is started
CMD [ "java", "-jar", "/apps/spring-petclinic-3.3.0-SNAPSHOT.jar" ]
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

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

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%