docker container run -it --name cont1 --mount "source=myvol,target=/jars" openjdk:8 /bin/bash
Check for the mounts available inside container using df -h
Now lets experiment with generating data inside the volume, remove the container and check in the volumes mount point if the data is still available
# Inside cont1
cd /jars
wget https://war-jar-files.s3-us-west-2.amazonaws.com/gameoflife.war
exit
# In Docker Host
docker container rm -f cont1
# Check for volumes
docker volume ls
docker volume inspect
# copy the mount point dir
ls <mountpointdir>
# two files should be available (spc.jar and gol.war)
Now lets mount the myvol to two containers and run the application simultaneously
docker container run --name cont3 --mount "source=myvol,target=/app" -d -p 8080:8080 openjdk:8 java -jar /app/spring-petclinic.jar
docker container run --name cont4 --mount "source=myvol,target=/app" -d -p 8081:8080 openjdk:8 java -jar /app/spring-petclinic.jar
docker container ls
docker volume ls
# remove all the containers
docker container rm -f $(docker container ls -a -q)
Data from Docker Volume will be removed only when the volume is removed