6

i'm trying to build a docker file with docker-compose up but i get error:

/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

here it is my docker file and docker-compose-yml file: 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"]

docker-compose:

version: '3'

services:
  redis:
    image: redis
    ports:
      - 6379
  web:
    build: .
    ports:
      - 8000:8000
    environment:
      - REDISTOGO_URL=redis://redis:6379
    depends_on:
      - redis
mohsen74x
  • 91
  • 1
  • 1
  • 3

4 Answers4

4

add this to your 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"]

on the other hand you need to setup a network in compose to be able to connect between the services using the service name.

LinPy
  • 16,987
  • 4
  • 43
  • 57
  • I tested it , it works. you need to delete your old images and build it again. it would also helpful if you say what does not worked – LinPy Aug 14 '19 at 13:18
  • i did it and i got this error: /root/.poetry/lib/poetry/_vendor/py2.7/subprocess32.py:149: RuntimeWarning: The _posixsubprocess module is not being used. Child process reliability may suffer if your program uses threads. "program uses threads.", RuntimeWarning) ERROR: Service 'web' failed to build: The command '/bin/sh -c poetry install && bundler install' returned a non-zero code: 1 – mohsen74x Aug 15 '19 at 06:20
  • try to add `pip install -U subprocess32` before `RUN poetry install` – LinPy Aug 15 '19 at 06:23
3

The poetry binary is not found because its location is not yet in the PATH environment variable. The poetry installer only adds a command in your .profile but it does not re-load those settings. In the Dockerfile after the poetry installalation command you need to add this line (it re-loads .profile)

RUN source ${HOME}/.profile

The poetry installer writes to ${HOME}/.profile

This has the benefit of not specifying that in this case $HOME is /root (in case you need to later a user, and not execute your server as root for security reasons)

aripy887
  • 107
  • 1
  • 4
  • 1
    This doesn't work. Each docker instruction starts a new shell in a new container. Whatever you sourced won't be carried over to the next step. [For more reference](https://stackoverflow.com/questions/40044810/linux-source-command-not-working-when-building-dockerfile) – GabrielChu May 28 '21 at 14:13
  • I tried this. Now it says > RUN source ${HOME}/.profile: 11 0.150 /bin/sh: 1: source: not found – sajid Aug 17 '22 at 08:19
0

AS per official documentation you need to set the env variable for poetry, there is also a new installation function/link but the new installer if for python 3 syntax

try

FROM python:[3x]

# ENV for poetry https://python-poetry.org/docs/configuration/#using-environment-variables
# make poetry create the virtual environment in the project's root, it gets named `.venv`
# and do not ask any interactive question
ENV POETRY_HOME="/opt/poetry" \
    POETRY_VIRTUALENVS_IN_PROJECT=true \
    POETRY_NO_INTERACTION=1

# Prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"

RUN apt-get update && apt-get install --no-install-recommends -y curl \
    && curl -sSL https://install.python-poetry.org | python

# Update poetry to latest version
RUN poetry self update

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"]

Mshka
  • 1,798
  • 1
  • 10
  • 19
0

Add this to the Dockerfile

ENV PATH="/root/.local/bin:$PATH"
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135