Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose containers fail and exit with code 127 missing /bin/env bash

I'm new to Docker so bear with me for any wrong term.

I have Docker Tools installed on Windows 7 and I'm trying to run a Docker compose file of a proprietary existing project stored in a git repository and that has probably been only run on Linux.

These are the commands I ran:

  1. docker-machine start
  2. docker-machine env
  3. @FOR /f "tokens=*" %i IN ('docker-machine env') DO @%i
    • this was output by step (2)
  4. docker-compose -f <docker-file.yml> up

Most of the Docker work has gone fine (image download, extraction, etc).

It is failing at container start, where some containers run fine - I recognize a working MongoDB instance since its log doesn't report any error - but other containers exit pretty soon with an error code, i.e.:

frontend_1 exited with code 127

Scrolling up a bit the console, I can see lines like:

No such file or directoryr/bin/env: bash

I have no idea where to go from here. I tried launching composer from a CygWin terminal, but got the same result.


Docker Compose file

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:
like image 808
watery Avatar asked Jul 23 '18 14:07

watery


People also ask

What is docker exit code 127?

Exit Code 127 means a command specified in the container specification refers to a non-existent file or directory.

How do I find my container exit code?

You can even get the exit code without any extra cruft by running docker inspect 61c6 --format='{{. State. ExitCode}}' . That's perfect for scripts because you can check the code easily.

How do I exit interactive container?

If you want to stop and exit the container, and are in an interactive, responsive shell - press ctrl+d to exit the session. You could as well type the exit command. TL;DR: press ctrl+c then ctrl+d - that means, keep the ctrl key pressed, type a c, and let go of ctrl.

Is docker compose deprecated?

You can still find Docker Compose V1 in the `master` branch. Compose V1 is marked as deprecated, and we'll begin patching only high-severity vulnerabilities or fixing critical bugs until the next milestone. Developers can continue to alias docker-compose to use docker compose.


1 Answers

It turned out it was a matter of file line endings, caused by git clone, as pointed out by @mklement0 in his answer to env: bash\r: No such file or directory question.

Disabling core.autocrlf then recloning the repo solved it.

like image 90
watery Avatar answered Oct 20 '22 15:10

watery