Skip to content

Instantly share code, notes, and snippets.

@jaywon
Last active April 9, 2018 11:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaywon/55406cf8e249843dbfea07bda77ebdbe to your computer and use it in GitHub Desktop.
Save jaywon/55406cf8e249843dbfea07bda77ebdbe to your computer and use it in GitHub Desktop.
Files used in Docker demo here: https://youtu.be/MncPj2ZHnD0
FROM alpine:latest
COPY writer.sh .
CMD ["/writer.sh"]

Steps to re-create

  1. docker build -t volume-tester .
  2. mkdir tmpvolume
  3. docker run -d -it --name voltest --mount type=bind,source="$(pwd)"/tmpvolume,target=/app --rm volume-tester:latest
  4. ls tmpvolume
  5. cat tmpvolume/*

Watch Video

Not in video but the container is gone at this point with the --rm flag but data persisted.

NOTE: --mount is preferred syntax in later version of Docker for bind mounts but the following would also work with the --volume or -v flags.

docker run -d -it --name voltest -v "$(pwd)"/tmpvolume:/app --rm volume-tester:latest
#!/bin/sh
cd /app
touch tester.txt
echo "TESTING TESTING" > tester.txt
echo "I EXIST" > /app/proof.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment