首页 > 解决方案 > 如何找到所有未命名的模块

问题描述

我得到了码头工人撰写:

version: '2'
services:
  elasticsearch:
    image: 'elasticsearch:7.9.1'
    environment:
      - discovery.type=single-node
    ports:
      - '9200:9200'
      - '9300:9300'
    volumes: 
      - /var/lib/docker/volumes/elastic_search_volume:/usr/share/elasticsearch/data:rw

当我运行时:

docker volume ls

我看不到任何结果。如何列出未命名的卷?

标签: docker

解决方案


docker volume ls正如您所展示的,它将列出所有存在的卷。

但是,在docker-compose.yml您显示的文件中,您没有创建命名或匿名卷。相反,您正在创建绑定挂载以将主机目录连接到容器文件系统空间。这些在技术 Docker 意义上不被视为“卷”,并且docker volume命令不会显示或操作它们。

直接接触/var/lib/docker通常不是最佳实践。最好让 Docker Compose 为您管理命名卷:

version: '2'
services:
  elasticsearch:
    volumes: 
      # No absolute host path, just the volume name
      - elastic_search_volume:/usr/share/elasticsearch/data:rw
volumes:
  elastic_search_volume:
    # Without this line, Compose will create the volume for you.
    # With this line, Compose expects it to already exist; you may
    # need to manually `docker volume create elastic_search_volume`.
    # external: true

推荐阅读