Unable to migrate database

Running under windows 10 using powershell.

After running

  • docker compose build
  • docker compose up

I wish to migrate the database. I tries two methods both with failed results’

method 1 (from powershell
docker-compose exec -w /var/www web ./vendor/bin/phinx migrate

method 2 (after running linux shell)
docker-compose exec -w /var/www web /bin/bash
vendor/bin/phinx migrate

The error is the same in both situations
/usr/bin/env: ‘php\r’: No such file or directory

I am at my wits end and am ready to look for am alternative to Docker

Hi

This is not a docker error, you try to run it like “vendor/bin/phinx migrate”, what happends if you use: “php vendor/bin/phinx migrate” instead?

I think at this point it doesn’t matter what you use. It looks like you have a carriage return character in your phinx phar file. The line endings on Windows is \r\n but it is \n on Linux. If you have built your PHP Composer dependencies on Windows and copied it into the Linux container it won’t work. Docker Desktop tries to hide magic behind the graphical interface, but you still have two different platforms. Make sure you run composer install on Linux, for example in a container during build or after the build using docker-compose exec

If you want to reproduce the issue on Linux:

printf "%s\r\n%s" '#!/usr/bin/env php' '<?php echo "HELLO";' > php.php
./php.php

The error:

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

update:

Sometimes, when you clone a git repository on Windows, your git client based on your settings will change the line endings. You can turn that off or use git in a container too. For example in a multi-stage build:

update2:

You can also enable WSL integration in Docker Desktop and use the Docker client and the git client from WSL so your line endings will be compatible with Linux.