DevOps Classroom Series – 30/Mar/2021

Multi Stage Docker builds

  • To build a docker image we need an application package, we build a application package on the build server and then use it in the docker file to build the application docker image.
  • The idea of multi stage builds is to use docker completely to build an application package and create a docker image.
  • Lets try to build the docker image for game of life Refer Here for the code of game of life
  • To build this application package we need
    • git to the code
    • java to be installed
    • maven to build the code
  • Manual Steps to get the application package:
git clone https://github.com/wakaleo/game-of-life.git
cd game-of-life
mvn package
  • Now after the package step is successful we get the gameoflife.war which can be used in the Dockerfile to build image
  • We have a docker image which is preinstalled with maven Refer Here
  • Refer Here for the Dockerfile created and then build the image
docker image build -t gameoflife:1.0 .

  • Docker first tries to build the stages in the above case it will build the mvn stage first and then it builds the docker image with the last FROM which will be what your image will have. the necessary files will be copied from stages into the Docker image depending on instructions

  • Lets run the container

  • Now lets try to build one more docker image using the multi staged build

  • Spring pet clinic

    • Manual steps for build the package:
    git clone https://github.com/spring-projects/spring-petclinic.git
    cd spring-petclinic
    mvn package
    
  • Refer Here for the docker file and build the image

docker image build -t spc:1.0 .

  • Now lets run the container

Install Docker on Linux

  • Ubuntu20:
    • Create a Ubuntu20 vm in any cloud or hypervisor
    • Login into ubuntu and update the packages
    sudo apt update
    
    • Refer Here for the official docs
    • Lets follow the repository model
  • Centos 7
    • Create a centos 7 instance in any cloud or hypervisor
    • Refer Here

Leave a ReplyCancel reply

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

Please turn AdBlock off
Social Network Integration by Acurax Social Media Branding Company

Discover more from Direct DevOps from Quality Thought

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

Continue reading

Exit mobile version
%%footer%%