DevOps Classroom notes 23/Jun/2025

Docker

Architecture

Running & Executing in containers in different modes

  • Containers by default run in attached mode which displys in the stdout, stderr in the current terminal
docker run --name web1 nginx
  • Containers can be run in the background without blocking terminal which is referred as detached mode, which returns a container id
docker run -d --name web2 nginx


* Other mode is interactive terminal, when you want to run a shell (we will discuss further later)
* Once the container is running we can execute commands in the container
* docker exec
* docker exec -it <bash|terminal>

Containerizing applications using Dockerfile

  • Dockerfile is a text file which contains instructions to create docker image
  • Instructions will have the following form
<INSTRUCTION> <VALUE>
  • Dockerfile has lots of instructions supported
  • Lets define some popular instructions
    • FROM
    • RUN
    • ADD | COPY
    • CMD
    • EXPOSE
    • LABEL
  • FROM: this instruction defines the base image
  • LABEL: This is used to add metadata
  • RUN: This runs a command during image building
  • CMD: This command executes when creating a container
  • ADD | COPY: They are used to copy files or directories into image
  • EXPOSE: This publishes the port on which your application is accessed.

Lets containerize the website used in previous class

  • Refer Here for previous classroom notes
  • Create a new folder called website and create a new file in this folder with name Dockerfile
  • Refer Here for the changes done
  • To build the docker ensure your are in the folder where Dockerfile exists
    & Execute
docker image build -t villa:1.0 .

  • The Dockerfile used is
FROM nginx
ADD html/ /usr/share/nginx/html
EXPOSE 80

Lets containerize the application

  • Refer Here for the spring pet clinic
  • The manual step to run this application is
    • Ensure jdk 17 is installed
    • java -jar spring-petclinic-3.3.0-SNAPSHOT.jar is the command to start the application
    • This application runs on port 8080
  • Approximate Dockerfile
FROM openjdk:17
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 java -jar /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%%