linuxdockernewlinecarriage-returnlinefeed

Docker - Files Contain Bad Line Terminators


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 <name>, 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: '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'
];

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


Solution

  • This should find files w/ CRLFs:

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