Skip to main content

Posts

Showing posts from August, 2024

Docker Volumes

Docker Volumes are a key feature that allow you to persist data generated by and used by Docker containers. Volumes are stored on the host filesystem outside the container's filesystem, so they are not deleted when the container is removed, making them ideal for persisting data like database files, logs, and configuration files. Example: Using Docker Volumes 1. Creating a Simple Container with a Volume Let's create a simple Docker container using the official nginx image and attach a volume to persist data. docker run -d --name my-nginx -v /mydata:/usr/share/nginx/html:ro -p 8080:80 nginx Explanation: -d : Runs the container in detached mode (in the background). --name my-nginx : Names the container my-nginx . -v /mydata:/usr/share/nginx/html:ro : Creates a volume that maps the host directory /mydata to the container directory /usr/share/nginx/html . The :ro option makes this volume read-only inside the container. -p 8080:80 : Maps port 8080 on the host to port 80 in the con