为什么 Docker 报告入口点文件不存在,而 ls 报告入口点文件存在?

Why does Docker report the entrypoint file doesn't exist when ls reports it does exist?

我正在使用 Docker v 19。我在 web/Dockerfile 的末尾有这个 ...

FROM python:3.7-slim
  
RUN apt-get update && apt-get install

RUN apt-get install -y dos2unix
RUN apt-get install -y libmariadb-dev-compat libmariadb-dev
RUN apt-get update \
    && apt-get install -y --no-install-recommends gcc \
    && rm -rf /var/lib/apt/lists/*

RUN python -m pip install --upgrade pip

WORKDIR /app/

COPY requirements.txt requirements.txt
COPY entrypoint.sh entrypoint.sh
RUN tr -d '\r' < entrypoint.sh > /app/entrypoint2.sh
RUN ls /app/entrypoint2.sh
RUN ls /app/
RUN python -m pip install -r requirements.txt

RUN ls /app/entrypoint.sh
RUN dos2unix /app/entrypoint.sh
RUN ls /app/entrypoint.sh

RUN chmod +x /app/*.sh
RUN ls ./
ENTRYPOINT ["./entrypoint2.sh"]

然而,当我运行“docker-compose up”(引用上面的内容)时,找不到“entrypoiet”文件,这令人困惑,因为上面的行( "ls ./") 表明它存在...

Step 14/19 : RUN ls /app/entrypoint.sh
 ---> Running in db8c11ce3fad
/app/entrypoint.sh
Removing intermediate container db8c11ce3fad
 ---> c23e69de2a86
Step 15/19 : RUN dos2unix /app/entrypoint.sh
 ---> Running in 9e5bbd1c0b9a
dos2unix: converting file /app/entrypoint.sh to Unix format...
Removing intermediate container 9e5bbd1c0b9a
 ---> 32a069690845
Step 16/19 : RUN ls /app/entrypoint.sh
 ---> Running in 8a53e70f219b
/app/entrypoint.sh
Removing intermediate container 8a53e70f219b
 ---> 5444676f45fb
Step 17/19 : RUN chmod +x /app/*.sh
 ---> Running in 5a6b295217c8
Removing intermediate container 5a6b295217c8
 ---> 8b5bfa4fd75a
Step 18/19 : RUN ls ./
 ---> Running in 9df3acb7deb7
entrypoint.sh
entrypoint2.sh
requirements.txt
Removing intermediate container 9df3acb7deb7
 ---> 009f8bbe18c8
Step 19/19 : ENTRYPOINT ["./entrypoint2.sh"]
 ---> Running in 41a7e28641a7
Removing intermediate container 41a7e28641a7
 ---> 34a7d4fceb8b

Successfully built 34a7d4fceb8b
Successfully tagged maps_web:latest
WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.

...
Creating maps_web_1   ... error

ERROR: for maps_web_1  Cannot start service web: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"./entrypoint2.sh\": stat ./entrypoint2.sh: no such file or directory": unknown

如何告诉 Docker 如何引用该入口点文件? docker-compose.yml 包含上述内容的文件部分如下

  web:
    restart: always
    build: ./web
    ports:           # to access the container from outside
      - "8000:8000"
    env_file: .env
    environment:
      DEBUG: 'true'
    command: /usr/local/bin/gunicorn directory.wsgi:application --reload -w 2 -b :8000
    volumes:
    - ./web/:/app
    depends_on:
      - mysql

根据提供的 Dockerfile 和 docker-compose 文件,您正在执行以下操作

  • 将文件(入口点+需求)复制到/app
  • 安装需要的包
  • 使用覆盖 /app 内容的卷启动容器,这是导致问题的原因。

要解决此问题,您必须执行以下操作之一

  • ./web 中的所有数据复制到 docker 图像并删除卷

Dockerfile : 添加以下行

WORKDIR /app/
COPY ./web /app

Docker-compose: 删除下面的行

   volumes:
    - ./web/:/app
  • 第二个选项是更改入口点的路径,使其不与卷冲突

Docker 文件

RUN tr -d '\r' < entrypoint.sh > /entrypoint2.sh
RUN chmod +x /entrypoint2.sh
ENTRYPOINT ["./entrypoint2.sh"]