Skip to content

Instantly share code, notes, and snippets.

@binario200
Last active May 28, 2016 05:00
Show Gist options
  • Save binario200/8158d07cec6ea4e2e443b3195d6477f9 to your computer and use it in GitHub Desktop.
Save binario200/8158d07cec6ea4e2e443b3195d6477f9 to your computer and use it in GitHub Desktop.
docker pull nginx
docker volume create --name barcelona
docker volumen ls
//running the container with the volume
docker run -it -v barcelona:/barcelona --name volumeslab nginx /bin/bash
//whithin the container go to the volume mounted
cd /barcelona
// create a file
touch file.txt
//exit the container
Ctrl+P and Ctrl+Q
//Inspect the volume
docker volume inspect barcelona
//go to the location of the volumen in you SO directory
cd /var/lib/docker/volumes/barcelona/_data
//for docker beta for mac https://forums.docker.com/t/host-path-of-volume/12277/2
// screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
//#user: root
//#password: <none>
//$ ls -ltrh /var/lib/docker/volumes
//create another file
touche file2.txt
//return to your running container
docker exec -it volumeslab /bin/bash
//list the container mointed directory
ls /barcelona
/// deleting the container
docker stop container-name
//check for the location of the volumen data at you SO
ls /volumes...
//list volumenes
docker volume ls
//remove the volume
docker volume rm volumename
docker volume ls
// create a Directory
mkdir webapp
cd webapp
//create a simple page
echo '<h1>Hola Dockerers!</h1>' > index.html
//run a container attaching your local folder to you container, at the nginx server directory
// take care of mapping your webapp folder
//check parameters like -d (run containers as daemon, -p use the port 80)
docker run -d -v ~/webapp:/usr/share/nginx/html --name mywebserver -p 80:80 nginx
//test your web app
culr http://localhost // for mac users
curl http://the-container-ip //use docker inspect continaerid | grep -i ip
//modified the html page
//and reload the page
/// ****** using a volume to share data amount containers
// create the volume to be shared
docker volume create --name shared-data
//raise one containers using the volume
docker run -it -v shared-data:/foo --name foo nginx /bin/bash
//create a file in the directory mapped to the volume
echo 'Tu dices "hola"' > /foo/file.txt
//Press Ctrl-P and then Ctrl-Q on you keyboard.
//This exits the container shell but leaves the container running.
//create other container using the same volume
docker run -it -v shared-data:/bar --name bar nginx /bin/bash
//modify the same file, check that for this continaer mounted volume is in /bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment