即使在 docker 中声明,卷也未使用 compose // 在假设卷的位置创建目录被复制到同一位置的其他位置

Volume not used even though declared in docker compose // creating a directory at location in assumed volume is copyied to other location in the same

我正在尝试使用在以下 docker-compose .yml 文件中一起定义的多个容器

services:  
  mobile_app: 
    container_name: mobile_app  # optional
    build:
      context: . 
      dockerfile: Dockerfile  # optional, default is Dockerfile in context
    ports:
      - 19000:19000 
      - 19001:19001
      - 19002:19002
    environment:
      - EXPO_DEVTOOLS_LISTEN_ADDRESS=0.0.0.0
      # - CHOKIDAR_USEPOLLING=true # Drains batterty, to be checked without usage, used for hot reload
      - REACT_NATIVE_PACKAGER_HOSTNAME=<?????????> # TODO: USE YOUR IPV4 address without any port
      - MONGODB_CONNSTRING=mongodb://root:secret@mongodb # (experimental)
    volumes:
      - type: volume
        source: sihv
        target: /root/app/
        volume:
          nocopy: true
      # - code:/root/workspace/app # TODO: change to your workspace
  auth_server:
    container_name: auth_server
    build:
      context: .
      dockerfile: Dockerfile.auth_server
    ports:
      - 1111:1111
    volumes:
      - type: volume
        source: sihv
        target: /root/servers/auth
        volume:
          nocopy: true
      # - code:/root/workspace/servers/auth
  mongodb:
    container_name: mongodb
    image: mongo
    ports:
      - 27018:27017
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=secret
      - MONGO_INITDB_DATABASE=db
    volumes:
      - "C:\Users\Public\db:/data/db" # mount is in the local machine
volumes:
  sihv:
    external: true

当我启动它时,它运行良好

但是 docker 仪表盘中的 sihv 是空的

另一个

当我尝试附加到多个 .devcontainer.jsons 时,存储为以下文件结构

当我在不同的 vscode windows 上分别打开多个 devcontainer 并创建一个名为“a”的目录时,它反映在同一卷中的这些多个位置

有没有办法解决这两个问题..? docker compose 文件中的声明有什么问题吗??

把上面的docker-compose.yml改成下面的就可以了

services:  
  mobile_app: 
    container_name: mobile_app  # optional
    build:
      context: . 
      dockerfile: Dockerfile  # optional, default is Dockerfile in context
    ports:
      - 19000:19000 
      - 19001:19001
      - 19002:19002
    environment:
      - EXPO_DEVTOOLS_LISTEN_ADDRESS=0.0.0.0
      - REACT_NATIVE_PACKAGER_HOSTNAME=<????????> # TODO: USE YOUR IPV4 address without any port
      - MONGODB_CONNSTRING=mongodb://root:secret@mongodb # (experimental)
    volumes:
      - type: volume
        source: sih_mobile_app
        target: /root/app/
        volume:
          nocopy: true
      # - code:/root/workspace/app # TODO: change to your workspace
  auth_server:
    container_name: auth_server
    build:
      context: .
      dockerfile: Dockerfile.auth_server
    ports:
      - 1111:1111
    volumes:
      - type: volume
        source: sih_server_auth
        target: /root/servers/auth
        volume:
          nocopy: true
      # - code:/root/workspace/servers/auth
  mongodb:
    container_name: mongodb
    image: mongo
    ports:
      - 27018:27017
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=secret
      - MONGO_INITDB_DATABASE=db
    volumes:
      - sih_mongodbv:/data/db # mount is in the local machine
  sih_flask1:
    container_name: sih_flask1
    build:
      context: .
      dockerfile: Dockerfile.flask1
    ports:
      - 8012:8012
    volumes:
      - sih_flask1:/tf
  sih_flask2:
    container_name: sih_flask2
    build:
      context: .
      dockerfile: Dockerfile.flask2
    ports:
      - 8016:8016
    volumes:
      - sih_flask2:/tf
volumes:
  sih_mobile_app:
    name: sih_mobile_app
  sih_server_auth:
    name: sih_server_auth
  sih_mongodbv:
    name: sih_mongodbv
  sih_flask1:
    name: sih_flask1
  sih_flask2:
    name: sih_flask2