gpt4 book ai didi

linux - 以退出代码2退出的Docker容器 “sh can' t open 'start_script.sh':没有这样的文件或目录”

转载 作者:行者123 更新时间:2023-12-02 19:44:53 24 4
gpt4 key购买 nike

我有以下用于启动Django服务器的Dockerfile:

    FROM python:3.7.4-alpine3.10
LABEL maintainer = ******

ENV PYTHONUNBUFFERED 1S
ENV RUNNING_IN_DOCKER True

RUN apk add --update --no-cache build-base postgresql-client exiftool jpeg-dev zlib-dev gettext git openssl
RUN apk add --update --no-cache gcc libc-dev linux-headers postgresql-dev file-dev py-magic libffi-dev libxml2-dev

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

RUN mkdir /app

WORKDIR /app

CMD sh start_script.sh
和以下docker-compose.yml:
    version: '3'

services:
backend:
build: .
restart: always
ports:
- 127.0.0.1:****:****
env_file:
- .env
environment: &app-env
- POSTGRES_HOST=db
- POSTGRES_PORT=${POSTGRES_PORT}
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- REDIS_HOST=redis
- REDIS_PORT=${REDIS_PORT}
depends_on: &app-dep
- db
- redis
volumes: &app-vol
- ./app
db:
image: postgres:10-alpine
restart: always
ports:
- ${POSTGRES_PORT}:****
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- ${LOCAL_POSTGRES_DB_DATA}:/var/lib/postgresql/data
redis:
image: redis:5-alpine
command: ["redis-server", "--appendonly", "yes"]
restart: unless-stopped
ports:
- ${REDIS_PORT}:****
volumes:
- ${LOCAL_REDIS_DATA}:/data
当我尝试运行它时,我在docker-compose日志中得到以下输出:
    Attaching to api_backend_1, api_redis_1, api_db_1
backend_1 | sh: can't open 'start_script.sh': No such file or directory
backend_1 | sh: can't open 'start_script.sh': No such file or directory
backend_1 | sh: can't open 'start_script.sh': No such file or directory
backend_1 | sh: can't open 'start_script.sh': No such file or directory
backend_1 | sh: can't open 'start_script.sh': No such file or directory
backend_1 | sh: can't open 'start_script.sh': No such file or directory
db_1 |
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2020-09-25 09:14:20.936 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port ****
db_1 | 2020-09-25 09:14:20.936 UTC [1] LOG: listening on IPv6 address "::", port ****
db_1 | 2020-09-25 09:14:20.945 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-09-25 09:14:20.965 UTC [20] LOG: database system was shut down at 2020-09-25 09:14:10 UTC
db_1 | 2020-09-25 09:14:20.970 UTC [1] LOG: database system is ready to accept connections
redis_1 | 1:C 25 Sep 2020 09:14:20.818 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 25 Sep 2020 09:14:20.818 # Redis version=5.0.9, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 25 Sep 2020 09:14:20.818 # Configuration loaded
redis_1 | 1:M 25 Sep 2020 09:14:20.819 * Running mode=standalone, port=****.
redis_1 | 1:M 25 Sep 2020 09:14:20.819 # Server initialized
redis_1 | 1:M 25 Sep 2020 09:14:20.819 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1 | 1:M 25 Sep 2020 09:14:20.819 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1 | 1:M 25 Sep 2020 09:14:20.819 * Ready to accept connections
api_backend_1 exited with code 2
api_backend_1 exited with code 2
这是文件结构:
/ git_repository
| - /app
| - requirements.txt
| - Dockerfile
| - docker-compose.yml
| - start_script.sh PERMISSIONS: -rwxrwxr-x 1 ubuntu ubuntu 208 Sep 25 08:11
奇怪的是,我们有另一个服务具有完全相同的Dockerfile和正确运行的结构...
我唯一发现可能是错误的是,在Dockerfile中,在运行 /app之前将workingdir更改为 start_script.sh,但是将run命令更改为 CMD sh ../start_script.sh并没有改变错误。对我来说,requirements.txt的副本也没有意义,但这与该错误无关
在搜索时,我遇到了 this post about line endings,但该修复程序也对我不起作用。
我不确定如何从这里继续进行操作,或者我如何进一步调试它,是否有人看到问题或可以尝试的提示?

最佳答案

根据对我的问题的评论,我使用docker-compose run backend sh检查我的容器。事实证明,我确实没有将任何源代码或start_script.sh复制到我的容器中。我对Dockerfile进行了更改以使其正常工作:

FROM python:3.7.4-alpine3.10
LABEL maintainer = ******

ENV PYTHONUNBUFFERED 1S
ENV RUNNING_IN_DOCKER True

RUN apk add --update --no-cache build-base postgresql-client exiftool jpeg-dev zlib-dev gettext git openssl
RUN apk add --update --no-cache gcc libc-dev linux-headers postgresql-dev file-dev py-magic libffi-dev libxml2-dev

RUN mkdir /app
COPY ./start_script.sh /app/start_script.sh. --------> Copy the start_script.sh
COPY ./requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

COPY . /app --------> Copy the source code
WORKDIR /app

CMD sh start_script.sh

关于linux - 以退出代码2退出的Docker容器 “sh can' t open 'start_script.sh':没有这样的文件或目录”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64061797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com