简体   繁体   中英

starting container process caused: exec: "uvicorn": executable file not found in $PATH: unknown

I'm trying to Dockerize my FastApi app, but it crashes with this error right after I run the command:

docker-compose -f local.yml up -d

Can anyone help me, please?

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 file :

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"

Error:

Cannot start service core: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "uvicorn": executable file not found in $PATH: unknown

In my case I add commands poetry run and it's works.

services:
 api:

  ...

  command: [
    "poetry", "run",
    "uvicorn",
    "app:main",
    "--port", "5000"
  ]

Add to Dockerfile, ENV PATH /home/${USERNAME}/.local/bin:${PATH} ,
before RUN pip install -r /home/app/web/$ENVTYPE.txt; mkdir /log; RUN pip install -r /home/app/web/$ENVTYPE.txt; mkdir /log; ,
by replacing ${USERNAME} with the container user.

If you don't know the current user, add RUN echo $(python3 -m site --user-base) somewhere in the Dockerfile. Then copy the output of that echo to replace /home/${USERNAME}/.local .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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