Skip to content

Instantly share code, notes, and snippets.

@s8sg
Created May 4, 2018 01:55
Show Gist options
  • Select an option

  • Save s8sg/9e0a10438964cf2506c17798dfc14406 to your computer and use it in GitHub Desktop.

Select an option

Save s8sg/9e0a10438964cf2506c17798dfc14406 to your computer and use it in GitHub Desktop.
  • Docker: Mount external drive to a volume and attach it to a container
docker volume create --name fred --opt /media/pi/mydrive
docker run -v fred:/var/www/html/ <container>
  • Docker: Mount directory from one container to another (specific dir) Mount using --volumes-from :
docker run -v /data/myfolder --name container1 image-name-1
docker run --volumes-from container1 image-name-2

Mount a specific dir:

# load directories in variables:
SRV1=$(docker inspect DATA1 | grep "vfs/dir" | awk '/"(.*)"/ { gsub(/"/,"",$2); print $2 }')
SRV2=$(docker inspect DATA2 | grep "vfs/dir" | awk '/"(.*)"/ { gsub(/"/,"",$2); print $2 }')
# mount these volumes by real directories instead of the --volumes-from
docker run -t -i -v $SRV1:/srv1 -v $SRV2:/srv2 ubuntu bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment