DevOps Classroom Series – 09/Feb/2020

Dockerfile instructions (others)

  • ARG:

    • is a variable that can be set during image build.
    • Scope: This ARG value will be available till the image is built
    • Refer Here
  • ENV:

    • this will be environment variable available in RUN container
    • These values can be set or changed while the container is created.
    • Refer Here
  • ONBUILD

  • STOPSIGNAL

  • HEALTHCHECK

  • .dockerignore

CI/CD Pipeline with Docker containers

Preview

  • Create a jenkins job
  • Get the latest code from git
  • Build the package using build tools like maven
  • Using the package build create the docker image
  • tag the docker image and send it to the registry
  • pull the docker image from registry and deploy using k8s/swarm etc

Registry

  • Collection of Docker Images
  • DockerHub:
    • Before uploading images (push) to docker hub, login into docker hub from command line

Sample Scenario: Push gameoflife to docker hub

  • Clone the code
git clone https://github.com/wakaleo/game-of-life.git
  • Build the code
mvn package
  • Create a Docker file at the root folder of game-of-life
FROM tomcat:8
LABEL owner=none
EXPOSE 8080
ADD ./gameoflife-web/target/gameoflife.war /usr/local/tomcat/webapps/gameoflife.war
CMD ["catalina.sh", "run"]
  • build the docker image
docker image build -t gol:1.0 .
  • login to docker hub
docker log
username: shaikkhajaibrahim
password
  • Now to push docker image to docker hub pattern is <username>/<imagename>:<tag>
docker image tag gol:1.0 shaikkhajaibrahim/gol:1.0
docker push shaikkhajaibrahim/gol:1.0

multistage builds

  • Multistage can be used to build applications and create docker images.

  • Refer Here

  • Lets build the application game of life using maven and create a docker image from the single docker file

FROM maven:3-jdk-8 as builder
RUN git clone https://github.com/wakaleo/game-of-life.git
RUN cd /game-of-life
WORKDIR /game-of-life
RUN mvn package


FROM tomcat:8
LABEL owner=none
EXPOSE 8080
COPY --from=builder /game-of-life/gameoflife-web/target/gameoflife.war /usr/local/tomcat/webapps/gameoflife.war
CMD ["catalina.sh", "run"]

Leave a Reply

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

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

Discover more from Direct DevOps from Quality Thought

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

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube