Create volume with docker volume with a custom Mou

2019-08-17 03:11发布

问题:

I need to create a volume with "docker volume" with a personal Mountpoint (mountpoint="/my/path/ not /var/lib/docker...) but i can't use plugin like local-persist

docker volume create -d local-persist -o mountpoint=/data/images --name=images

i need something like this but without plugin, maybe it can be done with --opt= and somethig after that, but i'm new at docker and linux. I hope someone can help me, just pay attention: i need "docker volume create" not something that let me use personal path in docker-compose.yml or something like this.

Edit

my docker compose is something like

version: '3.1'

services:

  grafana:
    image: grafana/grafana:5.3.4
    ports:
      - 3000:3000
    volumes:
      - grafanasql:/var/lib/grafana
      - grafanaconf:/etc/grafana
  ...
  ...
  volumes:
    grafanasql:
      external: true
    grafanaconf:
      external: true

If i let docker create volumes all its ok, but when i try to use external volume, with your docker volume create it doesnt work.

回答1:

The syntax is

docker volume create -d local -o o=bind -o device=/your/path

Or in docker-compose

volumes:
  mydata:
    driver: local
    driver_opts:
      o: bind
      device: /your/path