Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 Docker : /usr/bin/env: 'php\r': No such file or directory

I have a docker-compose.yml file where i defined the images and the build for php. Its made for a Symfony application with php, nginx and postgresql with postgis:

version: '2'
services: 

 front:
    image: nginx
    ports:
      - "81:80"
    links:
      - "engine:engine"
      - "db:db"
    volumes:
      - ".:/home/docker:ro"
      - "./docker/front/default.conf:/etc/nginx/conf.d/default.conf:ro"

 engine:
    build: ./docker/engine/
    volumes:
      - ".:/home/docker:rw"
      - "./docker/engine/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro"
    links:
      - "db:db"
    working_dir: "/home/docker"



  db:
    image: camptocamp/postgres:9.6
    ports:
      - "5433:5432"
    environment:
      - "POSTGRES_DB=pfe"
      - "POSTGRES_PASSWORD=admin"
      - "POSTGRES_USER=admin"
      - "PGDATA=/var/lib/postgresql/data/pgdata"

Everything works fine on Ubuntu but when i tryied to run the same environement onw windows 10 i got an error.

docker-compose exec engine bin/console doctrine:schema:create
    /usr/bin/env: 'php\r': No such file or directory
like image 578
Salim Ben Aissa Avatar asked Jun 11 '18 00:06

Salim Ben Aissa


3 Answers

I figure out a way to solve based on this: https://stackoverflow.com/a/2613834/3257568

tr -d '\015' <DOS-file >UNIX-file

So, I did this:

$ docker exec -it <container> bash
$ cd bin
$ tr -d '\015' <console >console.new
$ mv console console.old
$ mv console.new console

It's now working :)

like image 111
Maicon Carraro Avatar answered Nov 09 '22 05:11

Maicon Carraro


From the error message it seems you are facing issue related to EOL.

Try converting your scripts/files to UNIX formatted EOL.

You can use Sublime / Notepadd++ or any editor that supports this feature.
Or on unix platform you can try dos2unix.

like image 40
fly2matrix Avatar answered Nov 09 '22 05:11

fly2matrix


  1. Another possible fix for this kind of error is to add .gitattribues file to your project and set *.sh text eol=lf (on any file extension that is run inside your docker containers). This way git defaults on Windows won't mess your .sh files. Caution: you need to get fresh git pull for this to work.

  2. In my case the error was just running php script that did not have right permissions. So you chmod it beforehand or add php at the beginning. Ex: php bin/console

Both problems could lead to the same error.

like image 5
Alfred Avatar answered Nov 09 '22 05:11

Alfred