“Docker – Python Django 错误 entrypoint.sh:没有此文件或目录”

huangapple go评论63阅读模式
英文:

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 structure folder DRF_docker:

DRF_docker
|__server.py
|__venv
|__docker-compose.yml
|__backend
   |__requirements.txt
   |__docker
      |__docker_files
         |__Dockerfile
      |__entrypoints
         |__entrypoint.sh

I tried to remove #!/bin/sh and got the error exec /code/docker/entrypoints/entrypoint.sh: exec format error.
I tried a shorter path to /code/entrypoint.sh, but still, there was 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

答案1

得分: 0

你可以尝试更改ENTRYPOINT。
从:

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

到:

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

在Linux上运行Dockerfile时似乎存在问题:
https://github.com/bobby-didcoding/drf_course/issues/4

英文:

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

huangapple
  • 本文由 发表于 2023年5月10日 18:22:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76217284.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定