0

I'm using Docker 19 on Windows 10 (using Cygwin to run Docker). I have this web/Dockerfile ...

FROM python:3.7-slim

RUN apt-get update && apt-get install

RUN apt-get install -y dos2unix
RUN apt-get install -y libmariadb-dev-compat libmariadb-dev
RUN apt-get update \
    && apt-get install -y --no-install-recommends gcc \
    && rm -rf /var/lib/apt/lists/*

RUN python -m pip install --upgrade pip

WORKDIR /app/

COPY requirements.txt requirements.txt

COPY entrypoint.sh entrypoint.sh

RUN tr -d '\r' < /app/entrypoint.sh > /app/entrypoint2.sh
RUN python -m pip install -r requirements.txt

RUN grep '\r' /app/entrypoint.sh
RUN dos2unix /app/entrypoint.sh
RUN grep '\r' /app/entrypoint.sh

ENTRYPOINT ["bash", "/app/entrypoint.sh"]

and the entrypoint.sh file referenced looks like

#!/bin/bash
set -e

python manage.py migrate
python manage.py migrate directory
python manage.py docker_init_db_data

exec "$@"

But I guess there are some "\r" line endings that causes running "docker-compose up" on Windows to die. In my above file, I have

RUN dos2unix /app/entrypoint.sh

But I guess this doesn't do it, because running "docker-compose up" results in

web_1     | set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
web_1     | /app/entrypoint.sh: line 3: $'\r': command not found
web_1     | Unknown command: 'migrate\r'. Did you mean migrate?
web_1     | Type 'manage.py help' for usage.

How do I properly replace "\r" line endings in my shell script so that I can properly run my Dockerfile on Windows (and ideally all other) platforms?

Dave
  • 17,420
  • 96
  • 300
  • 582
  • The simplest is to write a small script (use python since you already have it) to fix the file, if your dos2unix utility is buggy. – ddbug Sep 28 '20 at 23:59

1 Answers1

0

I had same issue and with typing the commands in one line and separating them with && solved the problem.

in your case it would be:

python manage.py migrate --noinput && python manage.py migrate directory && python manage.py docker_init_db_data &&

hope it will solve your problem.