DevOps Classroomnotes 02/Sep/2023

Docker contd

Layers in Docker Image

  • Docker image is collection of read only image layers and meta-data

Experiments

  • Pull the alpine:3.17 image and inspect and focus on layers
docker image pull alpine:3.17
docker image inspect alpine:3.17

Preview
* Pull the jenkins/jenkins image and inspect and focus on layers

docker image pull jenkins/jenkins
docker image inspect jenkins/jenkins

Preview
Preview
* Use this Dockerfile and build the image with name exp:1.0

FROM alpine:3.17

Preview
* Now both alpine and exp:1.0 have same layers used
* Now consider the below dockerfile with name exp:1.1

FROM alpine:3.17
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/gameoflife.war /gameoflife.war

Preview
* Now as observed a new layer was created in exp:1.1
Preview
* Now build the exp:1.2 with the following Dockerfile

FROM alpine:3.17
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/gameoflife.war /gameoflife.war
RUN mkdir test
RUN cp /gameoflife.war /test/gameoflife.war

Preview
* Writing too many RUN instructions is not a good idea, so combine them. Use \ to increase Readability

FROM alpine:3.17
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/gameoflife.war /gameoflife.war
RUN mkdir test && \
    cp /gameoflife.war \
    /test/gameoflife.war \
    && java -version > version.txt
  • Docker container when created will union all the image layers and one writable layer to create a logical disk. This is done by Storage Drivers. The most popular one is overlay2.
    Preview
  • Refer Here for the article explaining layers and drivers
  • When we delete the container writable layer is deleted. To solve this we will learn docker volumes.

ENTRYPOINT and CMD in docker files

  • Docker container when starting will use the following to formulate the start up command
ENTRYPOINT CMD # Both Entrypoint and CMD exists in Docker
ENTRYPOINT
CMD
  • Whatever we have written in CMD can be overriten by passing arguments after image name during run/create
  • The Dockerfile used is
FROM alpine:3.17
CMD ["sleep", "1d"]

Preview

  • The Dockerfile is
FROM alpine:3.17
ENTRYPOINT ["sleep"]
CMD ["1d"]

Preview
* To chage entrypoint
Preview
* Difference between fork vs exec linux
* Difference between shell form and exec form in Dockerfile
* references
* Refer Here
* Refer Here

  • Problem: Docker container deletes the writable layer when deleted i.e. all the changes done by the contianer is lost

Docker volumes

  • Refer Here for blog article
  • We can be explicit and create volumes when our container is created automatically by adding VOLUME instruction in dockerfile
    Preview
  • Now create the container some-mysql and look at volumes
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql

Preview
* Now create a volume and mount it it mysql with same specific-mysql
Preview
Preview

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Wordpress Development Company

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