docker-compose 错误:FileNotFoundError:[Errno 2] 没有这样的文件或目录

Posted

技术标签:

【中文标题】docker-compose 错误:FileNotFoundError:[Errno 2] 没有这样的文件或目录【英文标题】:docker-compose Error: FileNotFoundError: [Errno 2] No such file or directory 【发布时间】:2021-09-28 14:43:12 【问题描述】:

我正在尝试用如下的 YML 文件编写 Docker 文件。

version: '3.6'
services:
  postgres:
    image: postgres:12
    restart: always
    volumes:
    - db_data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: postgrespassword
  graphql-engine:
    image: hasura/graphql-engine:v2.0.3
    ports:
    - "8080:8080"
    depends_on:
    - "postgres"
    restart: always
    environment:
      HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
      ## enable the console served by server
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
      ## enable debugging mode. It is recommended to disable this in production
      HASURA_GRAPHQL_DEV_MODE: "true"
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
      ## uncomment next line to set an admin secret
      # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
volumes:
  db_data:

但出现以下错误:

hasura-ais docker-compose up -d
Traceback (most recent call last):
  File "site-packages/urllib3/connectionpool.py", line 677, in urlopen
  File "site-packages/urllib3/connectionpool.py", line 392, in _make_request
  File "http/client.py", line 1252, in request
  File "http/client.py", line 1298, in _send_request
  File "http/client.py", line 1247, in endheaders
  File "http/client.py", line 1026, in _send_output
  File "http/client.py", line 966, in send
  File "site-packages/docker/transport/unixconn.py", line 43, in connect
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "site-packages/requests/adapters.py", line 449, in send
  File "site-packages/urllib3/connectionpool.py", line 727, in urlopen
  File "site-packages/urllib3/util/retry.py", line 403, in increment
  File "site-packages/urllib3/packages/six.py", line 734, in reraise
  File "site-packages/urllib3/connectionpool.py", line 677, in urlopen
  File "site-packages/urllib3/connectionpool.py", line 392, in _make_request
  File "http/client.py", line 1252, in request
  File "http/client.py", line 1298, in _send_request
  File "http/client.py", line 1247, in endheaders
  File "http/client.py", line 1026, in _send_output
  File "http/client.py", line 966, in send
  File "site-packages/docker/transport/unixconn.py", line 43, in connect
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "site-packages/docker/api/client.py", line 205, in _retrieve_server_version
  File "site-packages/docker/api/daemon.py", line 181, in version
  File "site-packages/docker/utils/decorators.py", line 46, in inner
  File "site-packages/docker/api/client.py", line 228, in _get
  File "site-packages/requests/sessions.py", line 543, in get
  File "site-packages/requests/sessions.py", line 530, in request
  File "site-packages/requests/sessions.py", line 643, in send
  File "site-packages/requests/adapters.py", line 498, in send
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 67, in main
  File "compose/cli/main.py", line 123, in perform_command
  File "compose/cli/command.py", line 69, in project_from_options
  File "compose/cli/command.py", line 132, in get_project
  File "compose/cli/docker_client.py", line 43, in get_client
  File "compose/cli/docker_client.py", line 170, in docker_client
  File "site-packages/docker/api/client.py", line 188, in __init__
  File "site-packages/docker/api/client.py", line 213, in _retrieve_server_version
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
[18722] Failed to execute script docker-compose

【问题讨论】:

看起来它与hasura没有任何关系。看看这个:github.com/docker/compose/issues/7896 和这个:***.com/questions/64633015/… 【参考方案1】:

我在使用卷时遇到了同样的问题。我在已安装的卷中创建了文件夹并修复了它。

在我的 docker 里面,我有一个这样的文件夹:

/data/logs
/data/files

并且正在安装我的本地空/data 文件夹。在我的本地 /data 中创建 logsfiles 文件夹后,它已修复。

【讨论】:

【参考方案2】:

如果在 GNU/Linux 机器上安装了 snap-installed docker,请尝试运行:

 docker --version

那么如果错误是:

cannot update snap namespace: cannot create symlink in "/etc/docker": existing file in the way
snap-update-ns failed with code 1

运行:

sudo mv /etc/docker /etc/docker_backup
sudo snap refresh docker 

那么错误就不会再出现了。

【讨论】:

【参考方案3】:

遇到了同样的问题。出于某种原因,打开和关闭 Docker Desktop(我在 Mac 上)修复了它。不知道为什么。

【讨论】:

以上是关于docker-compose 错误:FileNotFoundError:[Errno 2] 没有这样的文件或目录的主要内容,如果未能解决你的问题,请参考以下文章

编程连接期间的 Docker-Compose 错误

docker-compose的pkg resources DistributionNotFound错误对应

keycloak 容器正在重新启动,但出现错误 docker-compose

Springboot 容器使用 docker-compose 连接到 mongo 容器的 503 错误代码

Mongoose 服务器选择错误 ECONNREFUSED 与 docker-compose

在 Rider 中从 docker-compose 调试 .net 核心容器是错误的