20

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
2
  • maybe the php command is not defined in your windows environment variables
    – Nutshell
    Commented Jun 11, 2018 at 7:04
  • Did you have a solution? Commented Aug 13, 2018 at 17:31

5 Answers 5

25

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

12

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.

8
  • 1
    They are formated as for Unix! But the issue that Docker can't make the php run in the container. It works for postgresql when i use: docker-compose exec db psql database name -U database user name Commented Jun 14, 2018 at 9:45
  • And as the built was made with docker on windows that runs on Linux containers in Hyper-V! omg this is really complicated Commented Jun 14, 2018 at 9:48
  • Do login into the container and execute the command inside container manually.
    – fly2matrix
    Commented Jun 14, 2018 at 9:50
  • 1
    docker-compose exec -it engine sh and then inside console try bin/console doctrine:schema:create
    – fly2matrix
    Commented Jun 14, 2018 at 9:51
  • Sorry but it doesnt work! it just shows me the help as the command is wrong Commented Jun 14, 2018 at 11:34
6
  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.

1
  • 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
    Commented May 12, 2021 at 2:29
1

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

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
    Commented May 24, 2020 at 17:46
1

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

1
  • 1
    Also don't forget to make file executable with: chmod +x bin/console Commented Nov 30, 2023 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.