DevOps Classroom Series – 29/Mar/2021

Docker Volume mounts

  • Docker Volume Mount types Preview
  • Lets create a docker volume for the apache html folder Preview Preview Preview
  • Start the container with a volume
docker container run -d --name apache1 -P --mount "source=apachehtml,target=/var/www/html" httpd:latest

Preview

  • Now lets verify the mount point in the docker container
docker container inspect apache1

Preview

  • Now lets create some files in the /var/www/html folder from the container Preview
  • Now lets create a new container and mount the same volume into same folder (-v)
docker container run -d --name apache2 -P -v 'apachehtml:/var/www/html' httpd:latest

Preview

  • Now lets delete all the containers
docker container rm -f $(docker container ls -a -q)

Preview

  • Now lets create a new container and use the same volume mount
docker container run -d --name apache3 -P --mount "source=apachehtml,target=/var/www/html" httpd:latest

Preview

  • Volume driver can help in creating volumes in the
    • nfs
    • cifs
    • cloud
  • We need to install volume plugins and then use the volume driver while creating the volume
  • Refer Here for the official docs
  • Sample AWS Volume plugin Refer Here
  • Azure volume driver Refer Here
  • Lets create a Postgres container with volume mounted so that we can preserve the data
  • postgres stores the data in the folder /var/lib/postgresql/data
  • Lets create a postgres container Refer Here Preview
  • Now lets use exec command to create some data in the database Preview Preview
  • Containers can run applications of two types
    • Stateless: These applications donot store any data locally, so we dont need volumes for them
    • Stateful: these applications store the data and this data needs to be preserved so for stateful applications we use docker volumes
  • Useful docker commands
    • docker system df: This command will help in findng out the size of all docker objects in the Host Preview
    • To get more detailed information use docker system df -v Preview
  • To view the logs we can use the docker Preview
  • The other approach of storing logs is create a volume for the /var/logs folder and then export the logs from the docker host to central logs.
  • The other approach is to have a log client inside the container running which exports logs to centralized log server.
  • For tempfs mount Refer Here

Next Steps

  • Multi Staged build
  • docker networking
  • docker compose
  • intro to docker swarm
  • kubernetes
  • helm
  • openshift

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube