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?