Completek8s Classroomnotes 08/Jul/2023

Docker Networking

  • Refer Here for contianer networking model
  • Docker implements network with the libnetwork component which is implementation of CNM.
  • Docker daemon interacts with lib network.
  • Docker implements networking based on drivers
  • Refer Here for drivers and usecases
  • Refer Here this article from direct devops
  • Bridge: Bridge is generally a networking device that creates a single netowrk multiple network segments. Docker implements brigde network in linux as default network
    Preview
  • Lets create our own bridge network
    Preview
  • lets create two containers (C1 and C2) in default bridge, exec into C1 and ping C2 by name and ip
    Preview
  • As we see, we are able to reach other container by its ip not by name.
  • Lets attach container C1 and C2 to the bridge network which we created. Now ping
    Preview
  • we can ping other container by name and ip address

Activity1: Build a spring petclinic jar

  • Create a linux vm with atleast 2 vcpus and 4 GB RAM
  • install java 17
  • install maven
  • clone spring petclinic
git clone https://github.com/spring-projects/spring-petclinic.git
cd spring-petclinic
mvn package
  • Building packages can be done as part of building images this lead to something which we call as multi stage building
  • Refer Here for multistage building
  • Lets do that in phases, Create a new empty directory and add a Dockerfile
FROM maven:3-amazoncorretto-17 AS builder
COPY ./spring-petclinic /spring-petclinic
RUN cd /spring-petclinic && \
    mvn package
#  /spring-petclinic/target/spring-petclinic-3.1.0-SNAPSHOT.jar


FROM alpine:3.18.2
LABEL author=shaikkhajaibrahim
ARG JAVA_PACKAGE=openjdk17-jdk
ARG USER=spc
ARG HOME_DIR=/spc
ARG USER_SHELL=/bin/sh
RUN apk update && \
        apk add ${JAVA_PACKAGE} && \
        echo ${JAVA_TEST}
RUN adduser -h ${HOME_DIR} -s ${USER_SHELL} -D ${USER}
USER ${USER}
WORKDIR ${HOME_DIR}
COPY --from=builder --chown=${USER}:${USER} /spring-petclinic/target/spring-petclinic-3.1.0-SNAPSHOT.jar  spring-petclinic-3.1.0-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java"]
CMD ["-jar", "spring-petclinic-3.1.0-SNAPSHOT.jar"]
  • Exercise: Write a multi-staged build for nopcommerce Refer Here
    • this requires dotnet7 for building the code
    • dotnet build <path to sln>
  • Refer Here for the YAML tutorial

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner