9

This dockerfile works as expected. But the problem is that I am not able to change the source of volume.

version: "3.5"
services:
  mysql:
    environment:
      MYSQL_ROOT_PASSWORD: india3391
    image: shantanuo/mysql:5.7
    ports:
    - mode: ingress
      target: 3306
      published: 3391
      protocol: tcp
    volumes:
    - type: volume
      source: dbvol
      target: /var/lib/mysql
volumes:
  dbvol: {}

It seems to create a directory_name + volume_name folder in default docker installation that looks like this...

"Source": "/var/lib/docker/volumes/hashi1_dbvol/_data",

Is there a way to change this path?


Update:

# cat docker-compose.yml
version: "3.5"
services:
  mysql:
    environment:
      MYSQL_ROOT_PASSWORD: india3391
    image: shantanuo/mysql:5.7
    ports:
    - mode: ingress
      target: 3306
      published: 3391
      protocol: tcp
    volumes:
    - type: volume
      source: dbdata
      target: /var/lib/mysql

volumes:
  dbdata:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: '/srv4/db-data'

This compose file will work only if I first create the mount directory

mkdir -p /srv4/db-data

The volume parameter of docker run command will create this directory on the fly. Why is docker compose not able to create the directory?

shantanuo
  • 31,689
  • 78
  • 245
  • 403
  • Would https://stackoverflow.com/a/36194901/6309 help? Or using a symlink? (https://stackoverflow.com/questions/36014554/how-to-change-the-default-location-for-docker-create-volume-command#comment63223906_36014554) – VonC Jun 27 '18 at 09:14
  • The answer is there: https://stackoverflow.com/questions/36387032/how-to-set-a-path-on-host-for-a-named-volume-in-docker-compose-yml Let me know it this is what yo want. – godambrosio Jun 27 '18 at 12:19
  • @godambrosio I have updated my question. That answer is correct but unlike docker run, I need to first create a directory on host machine. Can this step be avoided? – shantanuo Jun 28 '18 at 07:22
  • 1
    I think this feature has been removed on request. for more detail : https://github.com/docker/compose/issues/2781 – chintan thakar Jun 29 '18 at 06:09
  • @chintanthakar That page suggest that docker run does not create directory which is not the case. Right? Automatic dictionary creation is a great feature. User should have that option through a parameter. – shantanuo Jun 29 '18 at 10:51

0 Answers0