Completek8s Classroomnotes 06/Jul/2023

Docker Instructions

  • ADD: Refer Here for official docs
    • Can download the contents from context/local folders as well as URLs, Recently support for git repos is also added
  • COPY: Refer Here for official docs

    • Can download the contents from context/local folders
  • Docker build context: This is set of the files located in specific PATH or URL specified during docker image build

Copy instruction

  • Using copy to copy the local file
FROM alpine:3.18.2
LABEL author=shaikkhajaibrahim
ARG JAVA_PACKAGE=openjdk11-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 --chown=${USER}:${USER} ./spring-petclinic-2.4.2.jar spring-petclinic-2.4.2.jar
EXPOSE 8080
ENTRYPOINT ["java"]
CMD ["-jar", "spring-petclinic-2.4.2.jar"]
  • Now build the image
    Preview
  • If we use Add instruction i can directly use URL
FROM alpine:3.18.2
LABEL author=shaikkhajaibrahim
ARG JAVA_PACKAGE=openjdk11-jdk
ARG USER=spc
ARG DOWNLOAD_LOCATION=https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/spring-petclinic-2.4.2.jar
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}
ADD --chown=${USER}:${USER}  ${DOWNLOAD_LOCATION} spring-petclinic-2.4.2.jar
EXPOSE 8080
ENTRYPOINT ["java"]
CMD ["-jar", "spring-petclinic-2.4.2.jar"]

Preview
* Lets try to build the docker image of some python app Refer Here
* Lets consider the following Dockerfile by using Add from git repo Refer Here

FROM python:3.7-alpine
LABEL author=KHAJA
LABEL blog=directdevops.blog
ARG HOME_DIR='/studentcourses'
ADD https://github.com/DevProjectsForDevOps/StudentCoursesRestAPI.git $HOME_DIR
ENV MYSQL_USERNAME='directdevops'
ENV MYSQL_PASSWORD='directdevops'
ENV MYSQL_SERVER='localhost'
ENV MYSQL_SERVER_PORT='3306'
ENV MYSQL_DATABASE='test'
EXPOSE 8080
WORKDIR $HOME_DIR
RUN pip install -r requirements.txt
ENTRYPOINT ["python", "app.py"]
  • This was failing we will fix this
  • We have build the images directly using docker image build Refer Here
    Preview
  • .DockerIgnore Refer Here

Running Docker Containers

  • The storage in docker is based on union of layers, which is done by special storage drivers. Now docker majorly uses overlay as a storage driver.
  • When the container is running the disk contents are union of all the read-only layers and one writable mounted as a single storage entity with the help of overlay
    Preview
  • When the docker container is removed then we loose writable layer
  • There are two kinds of applications

    • Stateless: These applications donot store state locally rather they rely on external systems such as databases, external mounts etc.
      • In modern applications all the microservices are stateless and they store state in some database
    • Stateful: These are applications which use local storage to store some data.
  • To solve this problem with data loss, we have Docker volumes.
  • Docker volumes ensure the data of the specific folder is persisted and has a life time beyond docker container

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner