H
H
HexUserHex2020-01-23 21:05:38
Docker
HexUserHex, 2020-01-23 21:05:38

Using volume in docker-compose?

I would be glad if someone explains in simple terms some incomprehensible moments of using volume in docker-compose.
Why is the last directive needed in this docker-conpose, what specific role does it play:

volumes:
  db-data:

- db-data in this example is this directory located in the same directory as docker-compose.yml?
- db-data:/var/lib/mysql/data
What is the difference from this entry (is it correct?):
- ./db-data:/var/lib/mysql/data

version: "3.7"
services:
wordpress:
image: wordpress
ports:
- "8080:80"
networks:
- overlay
deploy:
mode: replicated
replicas: 2
endpoint_mode: vip
mysql:
image: mysql
volumes:
- db-data:/var/ lib/mysql/data
networks:
- overlay
deploy:
mode: replicated
replicas: 2
endpoint_mode: dnsrr
volumes:
db-data:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2020-01-23
@HexUserHex

The last directive is needed to declare your own volume (volume), which will be created when the services are first started. Under each definition, you can add more options for this volume. For example, to declare that it is external and should have already been created manually in advance:

volumes:
  db-data:
    external: true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question