Docker Volumes Tutorial: How They Work

Docker Volumes Tutorial: How They Work

December 21, 2021
Tags:
docker

We'll show you how Docker volumes work. They allow you to mount a directory from your machine to the docker container. This is cool because any changes to files you make on your machine get immediately reflected within the docker container. We'll provide a demo and show you both ways to use Docker volumes. This tutorial goes through Docker Volumes and how to use them in 2 ways:

  1. -v option
  2. --mount option

Commands

docker run -v $(pwd)/data:/data -P --rm -d httpd
docker run -v $(pwd)/htdocs:/usr/local/apache2/htdocs -P --rm -d httpd
docker run --mount source=htdocs,target=/usr/local/apache2/htdocs -P --rm -d httpd

Links:

Explore lesson as part of a learning path

Get full access to these great resources

All for less than the price of coffee a day

44 courses
286 lessons
46+ hours

Get started with BoltOps Learn now and get access to easy and powerful lessons

BoltOps Tools