3

我正在尝试使用 docker-compose up 构建一个 docker 文件,但出现错误:

/bin/sh: 1: poetry: not found
ERROR: Service 'web' failed to build: The command '/bin/sh -c poetry install && bundler install' returned a non-zero code: 127

这是我的 docker 文件和 docker-compose-yml 文件: dockerfile:

FROM python:2.7

ENV LIBRARY_PATH=/lib:/usr/lib

RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python

WORKDIR /stream

ADD . /stream

CMD ["cat", "/etc/os-release"]


RUN poetry install && \
bundler install


EXPOSE 8000

CMD ["poetry", "run", "python", "manage.py", "runserver", "0.0.0.0:8000"]

码头工人撰写:

version: '3'

services:
  redis:
    image: redis
    ports:
      - 6379
  web:
    build: .
    ports:
      - 8000:8000
    environment:
      - REDISTOGO_URL=redis://redis:6379
    depends_on:
      - redis
4

2 回答 2

5

找不到二进制文件,poetry因为它的位置尚未在PATH环境变量中。安装程序只会在您的poetry文件中添加一个命令,.profile但不会重新加载这些设置。在安装命令Dockerfile之后,poetry您需要添加此行(它重新加载.profile

RUN source ${HOME}/.profile

安装poetry程序写入${HOME}/.profile

这样做的好处是没有指定在这种情况下$HOME/root(以防您以后需要一个用户,并且出于安全原因不以 root 身份执行您的服务器)

于 2019-08-14T13:23:13.663 回答
2

将此添加到您的 Dockerfile:

FROM python:2.7

ENV LIBRARY_PATH=/lib:/usr/lib

RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python

WORKDIR /stream

ADD . /stream

ENV PATH="${PATH}:/root/.poetry/bin"

RUN poetry install && \
bundler install


EXPOSE 8000

CMD ["/root/.poetry/bin/poetry", "run", "python", "manage.py", "runserver", "0.0.0.0:8000"]

另一方面,您需要设置一个networkincompose以便能够使用服务名称在服务之间进行连接。

于 2019-08-14T13:13:30.210 回答