简体   繁体   English

我的 docker-compose 文件有什么问题

[英]What is wrong with my docker-compose file

Can anybody help me to understand what is wrong with my docker-compose file:谁能帮我理解我的 docker-compose 文件有什么问题:

version: "3.7"

services:
  postgres:
    image: postgres:latest
    container_name: postgres
    restart: always
    volumes:
      - db-data:/var/lib/postgressql/data 
    environment:
      POSTGRES_PASSWORD: docker 
    ports:
      - "5400:5432" 

  api:
    restart: always
    build: ./api
    ports:
      - "5000:5000"
    volumes: 
      - .:/api
    entrypoint: ["python3", "app.py"]

  parser:
    restart: always
    build: ./parser
    ports:
      - 8000:8000
    volumes: 
      - .:/parser
    depends_on:
      - postgres
    entrypoint: ["python3", "run.py"]
volumes:
  db-data:
  api-data:
  parser-data:

Dockerfile: Dockerfile:

FROM python:3.8.5-buster
ENV APP_ROOT /src
RUN mkdir ${APP_ROOT}
WORKDIR ${APP_ROOT}}
ADD . ${APP_ROOT}
RUN pip install --upgrade pip
RUN pip3 install -r ${APP_ROOT}/requirements.txt  
EXPOSE 8000

Terminal reply: parser_1 |终端回复:parser_1 | python3: can't open file 'run.py': [Errno 2] No such file or directory python3:无法打开文件'run.py':[Errno 2]没有这样的文件或目录

My project tree我的项目树

do the following inside your project folder to find the relative path of your run.py:在项目文件夹中执行以下操作以查找 run.py 的相对路径:

find . -name 'run.py' -printf "%P\n"

then take that result and update the entrypoint in your docker file:然后获取该结果并更新 docker 文件中的入口点:

 entrypoint: ["python3", "relative_filepath_from_find_command_above_goes_here"]

You haven't mapped your local files to your parser container with volume: like you did in other services.您还没有将本地文件映射到带有volume:解析器容器:就像您在其他服务中所做的那样。 No such file or directory , it can't be found in your container. No such file or directory ,在您的容器中找不到。

EDIT: This is a simple example I've made with 3 files:编辑:这是我用 3 个文件制作的一个简单示例:

# Dockerfile
FROM python:3.7
RUN mkdir /app
COPY ./test.py /app
WORKDIR  /app
# docker-compose.yml
version: "3.7"
services:
    parser:
        build: .
        restart: always
        ports:
          - 8000:8000
        entrypoint: ["python3", "test.py"]
# test.py
print("ok")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM