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
RUN apt-get update && apt-get install openjdk-8-jdk -y && mkdir /myapp
VOLUME /myapp
ADD  /myapp/spring-petclinic.jar
# COPY ./spring-petclinic.jar  /spring-petclinic.jar
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


  • Refer Here for network file system as docker volume

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner