Wt is Docker volume - amresh087/newronaRepos GitHub Wiki
Volumes are the preferred mechanism for persisting data generated by and used by Docker container
Use of Volume
Decoupling container from storage. Shared volume (storage/data) among diff container and attach volume to container. If any time deleting container but volume does not delete.
.
-
docker volume --help
-
docker volume create
This is use for create volume in docker
-
docker volume ls
This is use for show list of volume
-
docker volume inspect
This is use for display internal details in volume
-
docker volume rm
This is use for rm volume from docker
-
docker volume prune
This is use for remove unused volume in docker
docker volume create myvolume1 docker volume ls docker volume inspect myvolume1 docker volume rm myvolume1 docker volume prune
Now for example pull Jenkins and run diff container and uses same volume.
docker pull jenkins
docker run --name myjenkins1 -v myvolume1:/var/jenkins_home -p 2019:8080 -p 5000:5000 jenkins
In this command --name myjenkins1 is used for giving the name of container
-v is used for volume its take two arguments source:destination here myvolume1 is source and /var/jenkins_home is destination
you can get jenkins storage directory data from dockerhub in jenkins image
-p 2019:8080
here 8080 is port of docker server port and exposing 2019 (localhost)
-p 5000:5000
here 5000 in jenkins API port and expose also on same port
Now you can access with public ip and port
After when you start jenkins on docker in console display that is Admin pass after you can set your user and pass
37c7438c6c9f444ebd5e40e92c03a907
Now you create one job Testjob in Jenkins
Now run another jenkins container for sharing volume
docker run --name myjenkins2 -v myvolume1:/var/jenkins_home -p 2020:8080 -p 6000:5000 jenkins
Now you can access http://18.191.149.29:2020/ here you can see one job already created called Testjob
Bind mount
Mean you can use physical location instead of volume
Now first create directory and give permission
sudo chmod 777 *
docker run --name myjenkins3 -v /home/ubuntu/jenkins:/var/jenkins_home -p 2021:8080 -p 7000:5000 jenkins
Now you can go to /home/ubuntu/jenkins and see the data are created