当前位置: 首页 > 知识库问答 >
问题:

启动容器进程导致:exec:“uvicorn”:在$PATH中找不到可执行文件:未知

钱志
2023-03-14

我试图将我的FastApi应用程序docker化,但在我运行命令docker compose-f local之后,它就因为这个错误崩溃了。有人能帮我吗?

Dockerfile:

FROM python:3.6.11-alpine3.11
ARG MYSQL_SERVER
ARG POSTGRES_SERVER
ENV ENVTYPE=local
ENV PYTHONUNBUFFERED 1
ENV APP_HOME=/home/app/web
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME

RUN apk update && apk add --no-cache bash
ADD /compose/scripts.sh $APP_HOME
ADD /requirements/$ENVTYPE.txt $APP_HOME
RUN chmod +x scripts.sh

RUN ./scripts.sh
RUN pip install -r /home/app/web/$ENVTYPE.txt; mkdir /log;

COPY /src/ $APP_HOME
CMD ["uvicorn", "app.main:app", "--reload", "--host", "0.0.0.0", "--port", "8080"]

local.yml文件:

version: '3.7'
services:
  nginx:
    env_file: .env
    build: 
      context: .
      dockerfile: ./compose/local/nginx.Dockerfile
    restart: always
    ports:
       - "${EX_PORT_NGINX:-8030}:80"
    volumes:
       - ./nginx/site.conf:/etc/nginx/conf.d/default.conf
  core:
    env_file: .env
    build: 
      context: .
      dockerfile: ./compose/local/core.Dockerfile
      args:
        MYSQL_SERVER: ${MYSQL_SERVER:-}
        POSTGRES_SERVER: ${POSTGRES_SERVER:-}
    restart: always
    volumes:
       - ./src:/home/app/web/
    logging:
       driver: "json-file"
       options:
          max-size: "5m"
          max-file: "10"

错误:

无法启动服务核心:无法创建填充:OCI运行时创建失败:container\u linux。go:380:启动容器进程导致:exec:“uvicorn”:在$PATH中未找到可执行文件:未知

共有1个答案

禹正阳
2023-03-14

添加到Dockerfile,ENV PATH /home/${USERNAME}/. local/bin:${PATH}
RUN pip install-r /home/app/web/$ENVTYPE. txt; mkdir /log;
通过将${USERNAME}替换为容器用户。

如果您不知道当前用户,请在Dockerfile中的某个位置添加RUN ech$(python3-m site--user-base)。然后复制该ech的输出以替换/home/${USERNAME}/. local

 类似资料: