10

Dockerfile

FROM python:3.7.4-alpine

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV LANG C.UTF-8
MAINTAINER "mail@gmail.com"


RUN apk update && apk add postgresql-dev gcc musl-dev
RUN apk --update add build-base jpeg-dev zlib-dev
RUN pip install --upgrade setuptools pip

RUN mkdir /code
WORKDIR /code

COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

#CMD ["gunicorn", "--log-level=DEBUG", "--timeout 90", "--bind", "0.0.0.0:8000", "express_proj.wsgi:application"]
ENTRYPOINT ["./docker-entrypoint.sh"]

docker-entrypoint.sh

#!/bin/bash

# Prepare log files and start outputting logs to stdout
touch /code/gunicorn.log
touch /code/access.log
tail -n 0 -f /code/*.log &

# Start Gunicorn processes
echo Starting Gunicorn.
exec gunicorn express_proj.wsgi:application \
    --name express \
    --bind 0.0.0.0:8000 \
    --log-level=info \
    --log-file=/code/gunicorn.log \
    --access-logfile=/code/access.log \
    --workers 2 \
    --timeout 90 \
    "$@"

Getting Error standard_init_linux.go:211: exec user process caused "no such file or directory" Need help. Some saying to use dos2unix(i do not know hoe to use it.)

2 Answers2

18

The "shebang" line at the start of a script says what interpreter to use to run it. In your case, your script has specified #!/bin/bash, but Alpine-based Docker images don't typically include GNU bash; instead, they have a more minimal /bin/sh that includes just the functionality in the POSIX shell specification.

Your script isn't using any of the non-standard bash extensions, so you can just change the start of the script to

#!/bin/sh
David Maze
  • 130,717
  • 29
  • 175
  • 215
  • After changing it, am getting *[2020-04-21 06:18:28 +0000] [10] [INFO] Booting worker with pid: 10*. What does it mean? I cann't solution for it anywhere. – Nurbek Batyrzhan uulu Apr 21 '20 at 06:56
  • That seems like normal output from `gunicorn` and I don't think you need to do anything about it. Just start making requests. – David Maze Apr 21 '20 at 09:43
4

This can also happen if the line endings of the script is wrong, i.e. \r\n instead of \r

this can be checked using the file path/to/script.sh command which tells if the script has CR-LF line endings

If its a one off script dos2unix can be used to change it to \r\n to \n

If its a git repository setting the autocrlf option to input would work

How to change line-ending settings

tejas
  • 1,795
  • 1
  • 16
  • 34
  • Thank you! Saved me days of clueless researches!! – It's a pretty uncommon solution but that was my tricky-to-diagnose problem. My project worked on Linux and MacOS, but **was failing in running the shel scripts, when cloned and rebuilt on Windows (WSL)**. Adding `*.sh eol=lf` and `*.bat eol=crlf` into a newly create `.gitattributes` (committed to the repository), solved the issue on the Windows machine after a `git pull --rebase` to get the attributes rules (hence fixing the line-ending when dealing with `git-checkout` of shell scripts). – Kamafeather Oct 26 '20 at 14:58