Suggest an editImprove this articleRefine the answer for “How to mount a volume in a container?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)A **volume** is mounted into a container using the `-v` (or `--mount`) flag when starting the container. **Key point:** to mount a volume, specify `-v volume_name:path_in_container`, or do the same in `docker-compose.yml`.Shown above the full answer for quick recall.Answer (EN)ImageA volume is mounted into a container using the `-v` (or `--mount`) flag when starting the container. The formula is simple: ```javascript docker run -v <volume_name>:<path_inside_container> image_name ``` ### Example Let's create a volume and mount it into a container: ```bash docker volume create mydata docker run -d -v mydata:/usr/share/data nginx ``` - `mydata` - the volume on the host - `/usr/share/data` - the folder inside the container - `nginx` - the image Now everything the container writes to `/usr/share/data` will be stored in the volume and will not disappear when the container is recreated. ### In docker-compose.yml `compose` uses the same principle: ```yaml services: app: image: nginx volumes: - mydata:/usr/share/data volumes: mydata: ``` --- In short: to mount a volume, specify `-v volume_name:path_in_container`, or do the same in `docker-compose.yml`.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.