[英]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.我有一个 docker-compose.yml 文件,我在其中定义了 php 的图像和构建。 Its made for a Symfony application with php, nginx and postgresql with postgis:
它是为带有 php、nginx 和 postgresql 和 postgis 的 Symfony 应用程序制作的:
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.在 Ubuntu 上一切正常,但是当我尝试在 Windows 10 上运行相同的环境时,出现错误。
docker-compose exec engine bin/console doctrine:schema:create
/usr/bin/env: 'php\r': No such file or directory
I figure out a way to solve based on this: https://stackoverflow.com/a/2613834/3257568我想出了一种解决方法: 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 :)它现在正在工作:)
From the error message it seems you are facing issue related to EOL.从错误消息看来,您遇到了与 EOL 相关的问题。
Try converting your scripts/files to UNIX formatted EOL.尝试将您的脚本/文件转换为 UNIX 格式的 EOL。
You can use Sublime / Notepadd++ or any editor that supports this feature.您可以使用 Sublime / Notepadd++ 或任何支持此功能的编辑器。
Or on unix platform you can try dos2unix .或者在 unix 平台上,您可以尝试dos2unix 。
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).此类错误的另一个可能解决方法是将 .gitattribues 文件添加到您的项目并设置
*.sh text eol=lf
(在您的 docker 容器内运行的任何文件扩展名上)。 This way git defaults on Windows won't mess your .sh files.这样,Windows 上的 git 默认值就不会弄乱您的 .sh 文件。 Caution: you need to get fresh git pull for this to work.
注意:您需要获取新的 git pull 才能使其工作。
In my case the error was just running php script that did not have right permissions.在我的情况下,错误只是运行没有正确权限的 php 脚本。 So you chmod it beforehand or add
php
at the beginning.所以你事先chmod它或者在开始时添加
php
。 Ex: php bin/console
例如:
php bin/console
Both problems could lead to the same error.这两个问题都可能导致相同的错误。
在我的情况下,删除chmod +x
转换,而是将php
添加到产生错误的命令的开头
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)然后替换此文件(将文件控制台移动到目录 bin)
For me working :-)对我来说工作:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.