Docker – 文件包含错误的行终止符

huangapple go评论62阅读模式
英文:

Docker - Files Contain Bad Line Terminators

问题

您在Windows 10上使用Docker设置了开发环境。我的Dockerfile和docker-compose.yml文件使用了php:8.2.2-apache,mysql:8.0.32,composer:2.5.3和phpMyAdmin:5.2.1。

我承认,让Docker运行起来,基本上模仿我的旧xampp开发环境,一直让人非常沮丧。

最近,我在composer.json中添加了robmorgan/phinx 0.13。最初,我从docker容器的终端运行了vendor/bin/phinx init,它成功创建了一个phinx.php文件。我停止了容器,修改了我的phinx.php文件以使用我的.env文件中的值。当我重新运行Docker,回到容器的终端运行vendor/bin/phinx create <name>时,我现在在终端中得到了这个错误:

usr/bin/env: 'php\r': 没有该文件或目录

我在几个地方都看到说这是因为文件使用了Windows的行终止符而不是Unix的行终止符。

问题在于我不明白哪个文件受到了影响。如何审查我的文件以找出罪魁祸首是哪个?

如果您感兴趣的话,这是我的docker-compose.yml和phinx.json:

version: '3.9'

services:
  webserver:
    build: ./docker
    image: -redacted-
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./www:/var/www/html
    links:
      - db

  db:
    image: mysql:8.0.32
    ports: 
      - "3306:3306"
    volumes:
      - ./database:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}

  composer:
    image: composer:2.5.3
    command: ["composer", "install"]
    volumes:
      - ./www:/app

  phpmyadmin:
    depends_on:
        - db
    image: phpmyadmin:5.2.1
    restart: always
    ports:
      - 8080:80
    environment:
      PMA_HOST: db
<?php
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$databaseName = $_ENV['MYSQL_DATABASE'];
$username = $_ENV['MYSQL_USER'];
$password = $_ENV['MYSQL_PASSWORD'];
return
[
    'paths' => [
        'migrations' => '%%PHINX_CONFIG_DIR%%/db/migrations',
        'seeds' => '%%PHINX_CONFIG_DIR%%/db/seeds'
    ],
    'environments' => [
        'default_migration_table' => 'phinxlog',
        'default_environment' => 'development',
        'production' => [
            'adapter' => 'mysql',
            'host' => 'localhost',
            'name' => $databaseName,
            'user' => $username,
            'pass' => $password,
            'port' => '3306',
            'charset' => 'utf8',
        ]
    ],
    'version_order' => 'creation'
];

我正在运行以下命令来加载Docker:docker-compose --env-file=./www/.env up

英文:

I setup a development environment using Docker on Windows 10. My Dockerfile and docker-compose.yml file uses php:8.2.2-apache, mysql:8.0.32, composer:2.5.3, and phpMyAdmin:5.2.1.

I will admit that getting Docker up and running to basically mimic my old xampp development environment has been incredibly frustrating.

Recently, I added robmorgan/phinx 0.13 to my composer.json. Initially, I ran from the docker container's terminal vendor/bin/phinx init and it successfully created a phinx.php file. I stopped the container, modified my phinx.php file to use values from my .env file. When I reran Docker, back into the container's terminal to run vendor/bin/phinx create &lt;name&gt;, I now get this error in the terminal:

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

I have read in several places that this is because files have the Windows line terminators instead of the Unix line terminators.

The issue is that I do not understand which file is affected. How can I audit my files to find out what is the culprit?

In case you are curious, this is my docker-compose.yml and phinx.json:

version: &#39;3.9&#39;

services:
  webserver:
    build: ./docker
    image: -redacted-
    ports:
      - &quot;80:80&quot;
      - &quot;443:443&quot;
    volumes:
      - ./www:/var/www/html
    links:
      - db

  db:
    image: mysql:8.0.32
    ports: 
      - &quot;3306:3306&quot;
    volumes:
      - ./database:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}

  composer:
    image: composer:2.5.3
    command: [&quot;composer&quot;, &quot;install&quot;]
    volumes:
      - ./www:/app

  phpmyadmin:
    depends_on:
        - db
    image: phpmyadmin:5.2.1
    restart: always
    ports:
      - 8080:80
    environment:
      PMA_HOST: db
&lt;?php
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv-&gt;load();
$databaseName = $_ENV[&#39;MYSQL_DATABASE&#39;];
$username = $_ENV[&#39;MYSQL_USER&#39;];
$password = $_ENV[&#39;MYSQL_PASSWORD&#39;];
return
[
    &#39;paths&#39; =&gt; [
        &#39;migrations&#39; =&gt; &#39;%%PHINX_CONFIG_DIR%%/db/migrations&#39;,
        &#39;seeds&#39; =&gt; &#39;%%PHINX_CONFIG_DIR%%/db/seeds&#39;
    ],
    &#39;environments&#39; =&gt; [
        &#39;default_migration_table&#39; =&gt; &#39;phinxlog&#39;,
        &#39;default_environment&#39; =&gt; &#39;development&#39;,
        &#39;production&#39; =&gt; [
            &#39;adapter&#39; =&gt; &#39;mysql&#39;,
            &#39;host&#39; =&gt; &#39;localhost&#39;,
            &#39;name&#39; =&gt; $databaseName,
            &#39;user&#39; =&gt; $username,
            &#39;pass&#39; =&gt; $password,
            &#39;port&#39; =&gt; &#39;3306&#39;,
            &#39;charset&#39; =&gt; &#39;utf8&#39;,
        ]
    ],
    &#39;version_order&#39; =&gt; &#39;creation&#39;
];

And I am running this to load Docker: docker-compose --env-file=./www/.env up

答案1

得分: 1

这应该查找带有CRLF的文件:

find -type f -print0 | xargs -0 file | grep CRLF
英文:

This should find files w/ CRLFs:

find -type f -print0 | xargs -0 file | grep CRLF

huangapple
  • 本文由 发表于 2023年2月16日 08:43:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466787.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定