0

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

  • The `app` container has a `platform:` override; do you need something similar for the `api` container as well? Can you simplify the setup and make it more reproducible by removing the Compose `volumes:`, `command:` override, and moving the Dockerfiles into the top-level directories? Especially the `volumes:` can result in overwriting the entrypoint script in the image with something different; your `RUN chmod` gets hidden by the bind mount. – David Maze May 10 '23 at 10:49

1 Answers1

0

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

Mogens
  • 548
  • 1
  • 3
  • 10
  • If you're going to do this then using a [shell form `ENTRYPOINT`](https://docs.docker.com/engine/reference/builder/#shell-form-entrypoint-example) is probably clearer; `ENTRYPOINT /code/.../entrypoint.sh` without the JSON-array syntax. Note that both forms will cause the `CMD` to be completely ignored. – David Maze May 10 '23 at 13:04
  • Thank you to answer my problem. But when I use your suggest to add "bash" and "-e", I could access to entrypoint.sh file but it send me new problem ` Unknown command: 'makemigrations\r'`. After several times fixed I solve problem `Unknown command 'makemigrations\r'` and can run image with `ENTRYPOINT ["bash", "/code/docker/entrypoints/entrypoint.sh"]` – JohnyDeen Agent May 11 '23 at 11:13