Skip to content

Instantly share code, notes, and snippets.

@samsalisbury
Last active November 23, 2022 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsalisbury/878cad64dc0070498922e70ae2cfc521 to your computer and use it in GitHub Desktop.
Save samsalisbury/878cad64dc0070498922e70ae2cfc521 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -Eeuo pipefail
echo "==> Creating volume 'vol1'..."
docker volume create vol1
echo "==> Writing 'hi!'..."
docker run --rm -v vol1:/mounted busybox sh -c 'echo "hi!" > /mounted/hi.txt'
echo "==> Appending 'hi2' (from a different container)..."
docker run --rm -v vol1:/mounted busybox sh -c 'echo "hi2" >> /mounted/hi.txt'
echo "==> Reading contents from a third container"
docker run --rm -v vol1:/mounted busybox sh -c 'cat /mounted/hi.txt'
# Output: $ ./share-docker-volumes
# ==> Creating volume 'vol1'...
# vol1
# ==> Writing 'hi!'...
# ==> Appending 'hi2' (from a different container)...
# ==> Reading contents from a third container
# hi!
# hi2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment