Docker classroom Series – 05/Oct/2019- Docker Volumes

Problem with Docker Persistence

  • Lets try to understand two kinds of applications

    • Stateless:
      • Which doesn’t use the local storage to store details
      • eg: Web Server
    • Stateful:
      • They use local storage to store necessary information
      • eg: Database Preview
  • We have to preserve the writable layers which are deleted when container is removed/terminated Preview

  • To Preserve the writable layer. Writable layer needs to be present in the Docker Host even after container is deleted.

  • Preserving the writable layer after container is terminated can be acheived by using

    • Bind mount
    • Volume
    • tmpfs
    • namedpipe
  • Refer here for complete info.

Docker Volumes

  • Volume will become a mount in the container.
  • Lifecycle of container will not impact Volume.
  • How can we create volume
    • Dockerfile:
      • Inside Dockerfile we have a instruction VOLUME
    • Using Docker CLI:
      • Create docker volumes by using docker volume
      • -v
      • –mount
      • For this section use examples mentioned here
  • Dockerfile Example:
FROM ubuntu:18.04
LABEL AUTHOR="khaja"
LABEL ORG="QT"
RUN apt-get update && apt-get install openjdk-8-jdk -y && mkdir /myapp
VOLUME /myapp
ADD https://qt-s3-new-testing.s3-us-west-2.amazonaws.com/spring-petclinic.jar  /myapp/spring-petclinic.jar
# COPY ./spring-petclinic.jar  /spring-petclinic.jar
EXPOSE 8080
CMD ["java", "-jar", "/myapp/spring-petclinic.jar"]
  • Terms to know

    • Named Volume:
    docker volume create myvol
    # use this
    docker container run -d -v myvol:/tools alpine sleep 1d
    
    • Anonymous Volume:
      • From Dockerfile
      • From commandline if -v option has no name attached docker container run -d -v /tools alpine sleep 1d

How to store volume Data outside of Docker Host

Preview

  • Refer Here for network file system as docker volume

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
Social Network Widget by Acurax Small Business Website 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