python-3.xdockerdocker-composedockerfiledocker-entrypoint

Docker - Python Django error entrypoint.sh: no such file or directory


I follow a tutorial about DRF backend and Docker use for test api. Link tutorial: https://www.youtube.com/watch?v=tujhGdn1EMI They were fully setup docker-compose and dockerfile. I am following but got error "exec /code/docker/entrypoints/entrypoint.sh: no such file or directory" on docker desktop.

The docker-compose.yml file:

version: '3.7'
services:

  api:
    build:
      context: ./backend
      dockerfile: docker/docker_files/Dockerfile
    restart: unless-stopped
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./backend:/code
    ports:
      - 8000:8000
    env_file:
      - .env

  app:
    build:
      context: .
      dockerfile: backend/docker/docker_files/Dockerfile_app
    platform: linux/amd64
    restart: unless-stopped
    ports:
      - 5000:5000

File Dockerfile:

FROM python:3.10

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

RUN set -e; \
    apt-get update ;\
    apt-get -y install netcat ;\
    apt-get -y install gettext ;

RUN mkdir /code
COPY . /code/
WORKDIR /code

RUN set -e; \
    /usr/local/bin/python -m pip install --upgrade pip ;\
    python -m pip install -r /code/requirements.txt ;\
    chmod +x /code/docker/entrypoints/entrypoint.sh ;

EXPOSE 8000
ENTRYPOINT ["/code/docker/entrypoints/entrypoint.sh"]

File entrypoint.sh:

#!/bin/sh
python manage.py makemigrations
python manage.py migrate
python manage.py test

exec "$@"

My struture folder DRF_docker |__server.py |__venv |__docker-compose.yml |__backend |__reuiqrements.txt |__docker |__docker_files |__Dockerfile |__entrypoints |__entrypoint.sh

I tried remove #!/bin/sh and got error exec /code/docker/entrypoints/entrypoint.sh: exec format error I tried shorty path to /code/entrypoint.sh and still no such file or directory


Solution

  • You could try changing the ENTRYPOINT. From:

    ENTRYPOINT [ "/code/docker/entrypoints/entrypoint.sh"]
    

    To:

    ENTRYPOINT ["bash", "-e", "/code/docker/entrypoints/entrypoint.sh"]
    

    There seems to be an issue when running the Dockerfile on Linux: https://github.com/bobby-didcoding/drf_course/issues/4