Docker 组合容器失败并退出,代码 127 丢失 /bin/env bash

wat*_*ery 5 windows docker docker-compose

我是 Docker 的新手,所以请容忍我的任何错误术语。

我在 Windows 7 上安装了 Docker 工具,我正在尝试运行存储在 git 存储库中的专有现有项目的 Docker 组合文件,该文件可能仅在 Linux 上运行。

这些是我运行的命令:

  1. docker-machine start
  2. docker-machine env
  3. @FOR /f "tokens=*" %i IN ('docker-machine env') DO @%i
    • 这是步骤(2)的输出
  4. docker-compose -f <docker-file.yml> up

大多数 Docker 工作进展顺利(图像下载、提取等)。

它在容器启动时失败,其中一些容器运行良好 - 我识别出一个工作 MongoDB 实例,因为它的日志没有报告任何错误 - 但其他容器很快退出并显示错误代码,即:

frontend_1 exited with code 127
Run Code Online (Sandbox Code Playgroud)

向上滚动控制台,我可以看到如下几行:

No such file or directoryr/bin/env: bash
Run Code Online (Sandbox Code Playgroud)

我不知道从这里去哪里。我尝试从 CygWin 终端启动 Composer,但得到了相同的结果。


Docker 撰写文件

version: "2"

services:
  frontend:
    command: "yarn start"
    image: company/application/frontend:1
    build:
      context: frontend
      dockerfile: docker/Dockerfile
    environment:
      <env entries>
    ports:
      - "3000:3000"
    volumes:
      - ./frontend:/opt/app

  backend:
    restart: "no"
    # source ~/.bashrc is needed to add the ssh private key, used by git
    command: bash -c "source ~/.bashrc && yarn run dev"
    image: company/application/backend:1
    build:
      context: backend
      dockerfile: docker/Dockerfile
    environment:
      <env entries>
    ports:
      - "4000:4000"
    volumes:
      - ./backend:/opt/app
      - ./:/opt:rw
      - ./.ssh/company_utils:/tmp/company_utils
    depends_on:
      - db

  generator-backend:
    restart: "no"
    # source ~/.bashrc is needed to add the ssh private key, used by git
    command: bash -c "source ~/.bashrc && npm run dev"
    image: company/generator/backend:1
    build:
      context: generator-backend
      dockerfile: docker/Dockerfile
    environment:
      <env entries>
    ports:
      - "5000:5000"
    volumes:
      - ./generator-backend:/opt/app
      - ./:/opt:rw
      - ./.ssh/company_utils:/tmp/company_utils
    depends_on:
      - db

  db:
    image: mongo:3.4
    volumes:
      - mongo:/data/db
    ports:
      - "27017:27017"

volumes:
  mongo:
Run Code Online (Sandbox Code Playgroud)

wat*_*ery 9

事实证明,这是由 引起的文件行结尾问题git clone,正如@mklement0 在env: bash\r: No such file or directory 的回答中指出的那样 question 的。

禁用core.autocrlf然后重新克隆回购解决了它。

  • 你刚刚拯救了我的一天!无法找出问题出在哪里。非常感谢 ! (2认同)