Difficulty: Beginner
Estimated Time: 10 minutes

In this lab, we will learn about running containers in interactive mode

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Named Volumes

Volumes

  • View available Docker Volumes on your host:
    docker volume ls

  • Create a new Named volume:
    docker volume create myvolume

  • Inspect your new volume:
    docker volume inspect myvolume

  • Store the mountpoint in a variable: export MOUNTPOINT=$(docker volume inspect myvolume | jq -r .[0].Mountpoint)

  • Run a new container with your Named volume mounted:
    docker container run --rm -it -v myvolume:/myloc/tmp --name mycontainer alpine

  • Create a temporary file in the container and exit:
    touch /myloc/tmp/test.txt exit

  • View the contents of Volume "myvolume" on the remote host. Notice we are mounting directly from the filesystem. docker container run --rm -v "${MOUNTPOINT}:/other/location" --name othercontainer alpine ls /other/location

  • Why can we not mount directly from the client? Hint echo $DOCKER_HOST

  • Why would you want to use a volume rather than a host mount?