Container Volume vs Bind Mount
People think a bind mount is just another volume, and it is not. A bind mount shows a host folder you chose inside the box. A volume is storage the container tool makes and looks after. Both can use the same -v flag, which is why they get mixed up. Use a bind mount to edit code, and a volume to keep a database's files.
Container Volume
Storage that outlives the container. Files kept there stay when the box is gone.
A container volume is storage that lives outside the container. The container sees it as a normal folder. When the container is deleted, the volume and its files stay. A new container can plug in the same volume and carry on. This is how a database in a container keeps its data.
Bind Mount
A host folder shared straight into a container. Edits on either side show on both.
A bind mount shares a folder from the host computer straight into a container. The container sees the folder at a path you choose. A change on either side shows up on the other at once. People use it to edit code on a laptop and run it in the container. Unlike a volume, the files live wherever the host keeps them.
In one line
- Container Volume
- Storage that outlives the container. Files kept there stay when the box is gone.
- Bind Mount
- A host folder shared straight into a container. Edits on either side show on both.