简体   繁体   中英

Setting volumes in docker-compose

I need a way to configure docker-compose to create a volume if it's missing, or in case it exists, use it. I need it to be persistent between versions, but I cannot assure it'll be configured upon initial configuration.

volumes:
  my_volume:
    external: true

I need to mount docker volume and not host directory. something like:

-v my_volume:/my_files

what's the best solution for such use-case?

You can use volume for each application or services you set in docker-compose file. For instance, I set a volume for my nginx server as like.

 volumes:
  - ./web/public:/srv/www/static
  - ./default.conf:/etc/nginx/conf.d/default.conf

The left side before colon are the path of the files or folder I want to store inside my docker image as volume whereas on right side I wrote the path where the files will be stored. When you build the file for first time it will create volume if in case if doesn't exist or use existing volume if it exist hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM