DevOps Classroomnotes 26/Aug/2023

Interacting with containers

  • Use the exec of the docker container command
  • We can execute interactive commands by using shell
  • Recommended Practice:
    • Run the container in a detached mode and use exec/logs for experimentation.

Containerization using Dockerfile

  • Dockerfile is a set of instructions which help in building the docker image.
  • To build a docker image (which is oci compliant) we need to
    • choose a base image
    • provide additional instructions to containerize the application
  • docker image build command does the image building process by creating a container, executing instructions and creating the docker image
  • The base image is required to set necessary stuff, if you want to build a docker image from scratch we can use base image scratch
  • The instructions in docker file INSTRUCTION <value>
  • Refer Here for whole set of instructions

FROM: set base image

LABEL: set metadata

RUN: execute instructions for configuring your application

CMD: run the command during startup

Expose: expose container ports

Image building ways of working

  • Create a newfolder or choose an existing folder. Create a file called as Dockerfile.
  • Generally Dockerfile is present with the source code.

Building springpetclinic

  • Refer Here for the first set of changes (
  • Now build the image with tag 1.0.0 and repo spc
  • The command is docker image build -t spc:1.0 .
  • Now add labels Refer Here for changeset and below for image building, lets use the same tag and repo
  • When we repeatedly use same repo and tags there is a chance that some earlier builded images will get a repo name and tag name as <none>
  • Refer Here for the changes done to download the spring petclinic into the docker image.
  • Now lets build the image with same repo spc and tag 1.0.1
  • the Failure wget not found represents the wget not present in the base image, So we have two options
    • find an alternative command
    • install wget
  • We have used the alternative to use curl Refer Here for changes
  • Now lets build the image with same repo spc and tag 1.0.1
  • Refer Here for adding the expose information.
  • Now build the image with same repo spc and tag 1.0.2
  • Now lets create the container from spc:1.0.2 and we observed the container went into exited state
  • Now add the CMD to start the application, build the image with repo spc and tag 1.0.3 Refer Here for the changes in Dockerfile
  • Note: 1.0.3 failed due to wrong argument Refer Here for fix
  • Now create the container using spc:1.0.4
  • Generally slim or alpine base images will reduce image size Refer Here for the changes to use alpine jdk 11 as a base image
  • Build the image with repo spc:1.0.0-slim
  • run the contianer

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner