0

Problem Description

I have a docker image which I build and run using docker-compose. Normally I develop on WSL2, and when running docker-compose up --build the image builds and runs successfully. On another machine, using Windows powershell, with an identical clone of the code, executing the same command successfully builds the image, but gives an error when running.

Error

    [+] Running 1/1
     - Container fastapi-service  Created                                                                              0.0s
    Attaching to fastapi-service
    fastapi-service  | exec /start_reload.sh: no such file or directory
    fastapi-service exited with code 1

I'm fairly experienced using Docker, but am a complete novice with PowerShell and developing on Windows more generally. Is there a difference in Dockerfile construction in this context, or a difference in the execution of COPY and RUN statements?

Code snippets

Included are all parts of the code required to replicate the error.

Dockerfile

    FROM tiangolo/uvicorn-gunicorn:python3.7

    COPY requirements.txt requirements.txt
    RUN pip install --no-cache-dir -r requirements.txt

    COPY ./start.sh /start.sh
    RUN chmod +x /start.sh

    COPY ./start_reload.sh /start_reload.sh
    RUN chmod +x /start_reload.sh

    COPY ./data /data
    COPY ./app /app

    EXPOSE 8000 

    CMD ["/start.sh"]

docker-compose.yml

    services:
      web:
        build: .
        container_name: "fastapi-service"

        ports:
          - "8000:8000"

        volumes:
          - ./app:/app
        command: /start_reload.sh

start-reload.sh

This is a small shell script which runs a prestart.sh if present, and then launches gunicorn/uvicorn in "reload mode":

    #!/bin/sh
    # If there's a prestart.sh script in the /app directory, run it before starting
    PRE_START_PATH=/app/prestart.sh

    HOST=${HOST:-0.0.0.0}
    PORT=${PORT:-8000}
    LOG_LEVEL=${LOG_LEVEL:-info}

    echo "Checking for script in $PRE_START_PATH"
    if [ -f $PRE_START_PATH ] ; then
        echo "Running script $PRE_START_PATH"
        . "$PRE_START_PATH"
    else 
        echo "There is no script $PRE_START_PATH"
    fi

    # Start Uvicorn with live reload
    exec uvicorn --host $HOST --port $PORT --log-level $LOG_LEVEL main:app --reload 

1 Answers1

0

The solution lies in a difference between UNIX and Windows systems, and the way they end lines. A discussion on the topic can be found [here]. (Difference between CR LF, LF and CR line break types?)

The presence/absence of these characters in the file, and configuration of the shell running the command leads to an error where the file being run is the Dockerfile start-reload.sh(CR-LF) but the file that exists is simply start-reload.sh, hence the no such file or directory error raised.