A container is temporary. When it stops, the files written inside it can disappear. A Docker volume stores data outside the container, so a database or uploaded file stays safe when the container is replaced.
Two common ways to use one
- Named volume: Docker manages the storage. Good for databases. Example: docker volume create mydata.
- Bind mount: a folder on your computer is shared with the container. Good while you are writing code.
Try it
Run a container that writes a file to a volume, stop it, then start a new container with the same volume. The file is still there. Then run the same test without a volume and see the file is gone.
Understand containers first, then move on to multi-container setups. Read DevOps for beginners: what to learn first, or see the cloud and DevOps course. Book a free demo class, and ask a counsellor for the current schedule.
