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

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

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:

  1. version: '3.7'
  2. services:
  3. api:
  4. build:
  5. context: ./backend
  6. dockerfile: docker/docker_files/Dockerfile
  7. restart: unless-stopped
  8. command: python manage.py runserver 0.0.0.0:8000
  9. volumes:
  10. - ./backend:/code
  11. ports:
  12. - 8000:8000
  13. env_file:
  14. - .env
  15. app:
  16. build:
  17. context: .
  18. dockerfile: backend/docker/docker_files/Dockerfile_app
  19. platform: linux/amd64
  20. restart: unless-stopped
  21. ports:
  22. - 5000:5000

File Dockerfile:

  1. FROM python:3.10
  2. ENV PYTHONUNBUFFERED 1
  3. ENV PYTHONDONTWRITEBYTECODE 1
  4. RUN set -e; \
  5. apt-get update ;\
  6. apt-get -y install netcat ;\
  7. apt-get -y install gettext ;
  8. RUN mkdir /code
  9. COPY . /code/
  10. WORKDIR /code
  11. RUN set -e; \
  12. /usr/local/bin/python -m pip install --upgrade pip ;\
  13. python -m pip install -r /code/requirements.txt ;\
  14. chmod +x /code/docker/entrypoints/entrypoint.sh ;
  15. EXPOSE 8000
  16. ENTRYPOINT ["/code/docker/entrypoints/entrypoint.sh"]

File entrypoint.sh:

  1. #!/bin/sh
  2. python manage.py makemigrations
  3. python manage.py migrate
  4. python manage.py test
  5. exec "$@"

My structure folder DRF_docker:

  1. DRF_docker
  2. |__server.py
  3. |__venv
  4. |__docker-compose.yml
  5. |__backend
  6. |__requirements.txt
  7. |__docker
  8. |__docker_files
  9. |__Dockerfile
  10. |__entrypoints
  11. |__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:

  1. version: '3.7'
  2. services:
  3. api:
  4. build:
  5. context: ./backend
  6. dockerfile: docker/docker_files/Dockerfile
  7. restart: unless-stopped
  8. command: python manage.py runserver 0.0.0.0:8000
  9. volumes:
  10. - ./backend:/code
  11. ports:
  12. - 8000:8000
  13. env_file:
  14. - .env
  15. app:
  16. build:
  17. context: .
  18. dockerfile: backend/docker/docker_files/Dockerfile_app
  19. platform: linux/amd64
  20. restart: unless-stopped
  21. ports:
  22. - 5000:5000

File Dockerfile:

  1. FROM python:3.10
  2. ENV PYTHONUNBUFFERED 1
  3. ENV PYTHONDONTWRITEBYTECODE 1
  4. RUN set -e; \
  5. apt-get update ;\
  6. apt-get -y install netcat ;\
  7. apt-get -y install gettext ;
  8. RUN mkdir /code
  9. COPY . /code/
  10. WORKDIR /code
  11. RUN set -e; \
  12. /usr/local/bin/python -m pip install --upgrade pip ;\
  13. python -m pip install -r /code/requirements.txt ;\
  14. chmod +x /code/docker/entrypoints/entrypoint.sh ;
  15. EXPOSE 8000
  16. ENTRYPOINT ["/code/docker/entrypoints/entrypoint.sh"]

File entrypoint.sh:

  1. #!/bin/sh
  2. python manage.py makemigrations
  3. python manage.py migrate
  4. python manage.py test
  5. 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。
从:

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

到:

  1. 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:

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

To:

  1. 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:

确定