Docker compose 将现有卷附加到docker容器

Docker compose 将现有卷附加到docker容器,docker-compose,Docker Compose,我创建了三卷: docker volume create -d local-persist -o mountpoint=/home/usr1/mongodb/data --name=mongodbvv1 docker volume create -d local-persist -o mountpoint=/home/usr2/mongodb/data --name=mongodbvv2 docker volume create -d local-persist -o mountpoint=/h

我创建了三卷:

docker volume create -d local-persist -o mountpoint=/home/usr1/mongodb/data --name=mongodbvv1
docker volume create -d local-persist -o mountpoint=/home/usr2/mongodb/data --name=mongodbvv2
docker volume create -d local-persist -o mountpoint=/home/user2/mongodb/data --name=mongodbvv3
我想告诉我的docker-compose.yml文件,使用这些现有卷,而不是创建新卷。我找不到这台自动取款机的文件

My docker-compose.yml:

version: '3.7'
services:

  mongo:
    container_name: mongodb1
    image: mongo:latest
    command: mongod --port 27017 --bind_ip 127.0.0.1,10.77.0.2
    restart: always
    ports:
        - 27048:27017
    expose:
         - 27017
    volumes: 
      - mongodbvv1: 
    networks:
      mongodvnet:
        ipv4_address: 10.77.0.2

  mongo2:
    container_name: mongodb2
    image: mongo:latest
    command: mongod --port 27018 --bind_ip 127.0.0.1,10.77.0.3
    restart: always
    ports:
        - 27049:27018
    expose:
         - 27018
    volumes: 
      - mongodbvv2:
    networks:
      mongodvnet:
        ipv4_address: 10.77.0.3

  mongo3:
    container_name: mongodb3
    image: mongo:latest
    command: mongod --port 27019 --bind_ip 127.0.0.1,10.77.0.4
    restart: always
    ports:
        - 27050:27019
    expose:
         - 27019
    volumes: 
      - mongodbvv3:
    networks:
      mongodvnet:
        ipv4_address: 10.77.0.4

networks:
  mongodvnet:
    driver: bridge
    ipam: 
     config: 
       - subnet: 10.77.0.0/16

volumes: 
    mongodbvv1:
       external: true
    mongodbvv2:
       external: true
    mongodbvv3:
       external: true 
错误:

ERROR: The Compose file './docker-compose.yml' is invalid because:
value 'device', 'o', 'type' do not match any of the regexes: '^x-'
driver_opts contains an invalid type, it should be an object
volumes 'type' is a required property
不,我的问题不是:

ERROR: The Compose file './docker-compose.yml' is invalid because:
value 'device', 'o', 'type' do not match any of the regexes: '^x-'
driver_opts contains an invalid type, it should be an object
volumes 'type' is a required property


您必须在卷名之后提到装入点

例如:

version: "3.7"
services:
  db:
    image: postgres
    volumes:
      - data:/var/lib/postgresql/data
volumes:
  data:
    external: true

yaml中缺少
/var/lib/postgresql/data
。添加它并尝试

创建的dbdata和myvolume驱动器正在使用docker volume create命令。下面的文章没有任何问题

version: "3.6"
services:
  db:
    image: mysql
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_DATABASE: {your_db}
      MYSQL_ROOT_PASSWORD: {your_password}
    volumes:
      - dbdata:/var/lib/mysql
  api:
    image: {your_image}
    ports:
      - "80:80"
    restart: always
    volumes:
      - myvolume:/app/log

volumes: 
    dbdata:
        # command to inform docker to use an existing volume
        external: true
    myvolume:
        # command to inform docker to use an existing volume
        external: true

但是,如果要使用现有卷,首先要创建卷。请看我问题的开头。另外,我尝试过这种方法,但效果不好。