19

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
namokarm
  • 668
  • 1
  • 7
  • 20
Salim Ben Aissa
  • 435
  • 1
  • 6
  • 21

5 Answers5

23

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 :)

Maicon Carraro
  • 499
  • 4
  • 12
11

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.

fly2matrix
  • 2,351
  • 12
  • 13
5
  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.

Alfred
  • 336
  • 6
  • 12
  • 3
    makes me angry that this is even necessary. Windows has no problem using unix line endings, nobody cares, and it only breaks things if you don't use them. Drives me nuts. – Brad May 12 '21 at 02:29
1

In my case removing the chmod +x conversion and instead adding php to the beginning of the command that produces the error

Ryan
  • 11
  • 1
  • I don't see any `chmod +x` in the question, thus this does not provide an answer to it. If you are referring to another answer, please indicate which one, otherwise it is better to explain the steps you have followed to answer the question on your side – gogaz May 24 '20 at 17:46
0

Try this:

tr -d '\15' < original_file > converted_file

In your case:

tr -d '\15' < bin/console > console

And next replace this file(move the file console to directory bin)

For me working :-)

Adrian
  • 379
  • 4
  • 10