Suggest an editImprove this articleRefine the answer for “How to declare a volume in docker-compose.yml?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)A **volume** is declared in `docker-compose.yml` in two places: inside the service, where the volume is mounted, and at the bottom of the file, where the volume's existence is declared. **Key point:** after `docker compose up`, Docker creates the volume itself and mounts it into the container.Shown above the full answer for quick recall.Answer (EN)ImageA volume is declared in `docker-compose.yml` in two places: ### **1. Inside the service (where the volume is mounted)** ```yaml services: app: image: nginx volumes: - mydata:/usr/share/nginx/html ``` Here `mydata` is the volume that is connected to the path inside the container. ### **2. At the bottom of the file (where the volume is described)** ```yaml volumes: mydata: ``` ### **What happens** - in the `services` section - we **mount the volume** into the container - in the `volumes` section - we **declare that the volume exists** ### **Summary** A complete minimal example: ```yaml services: app: image: nginx volumes: - mydata:/usr/share/nginx/html volumes: mydata: ``` After `docker compose up`, Docker creates `mydata` itself and mounts it into the container.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.