1

I have an error when building a Docker image. I didn't have this error until a few days ago and I don't really remember changing the Dockerfile, so I don't know what happened. Also, I am using Poetry, running in the Dockerfile the following commands (following this other Integrating Python Poetry with Docker post):

source $HOME/.poetry/env && poetry export -f requirements.txt | /venv/bin/pip install -r /dev/stdin

source $HOME/.poetry/env && poetry build && /venv/bin/pip install dist/*.whl

I tried to repeat the same steps manually in a Docker container and I encountered the same error.

Whenever I run "poetry run" or "poetry build" I got this error:

[OSError]
[Errno 8] Exec format error: '/app/.venv/bin/python'

I don't really know what to look at so I don't even know what information share with you here. Let me know.

Thanks

Dockerfile ( I cut it on the line that causes the crash):

FROM python:3.7.4-slim-stretch AS builder

RUN apt-get update -qq && \
  apt-get install -y --no-install-recommends \
  build-essential \
  curl \
  git

ARG MY_ENV
ARG DOCKER_HOST

ENV MY_ENV=${MY_ENV} \
  PYTHONFAULTHANDLER=1 \
  PYTHONUNBUFFERED=1 \
  PYTHONHASHSEED=random \
  PIP_NO_CACHE_DIR=on \
  PIP_DISABLE_PIP_VERSION_CHECK=on \
  PIP_DEFAULT_TIMEOUT=100 \
  POETRY_VERSION=1.0.0

RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python /dev/stdin --version $POETRY_VERSION
RUN python -m venv /venv
RUN mkdir app
WORKDIR ./app
COPY pyproject.toml poetry.lock ./
RUN /bin/bash -c "source $HOME/.poetry/env && poetry export -f requirements.txt | /venv/bin/pip install -r /dev/stdin"
COPY . .
RUN /bin/bash -c "source $HOME/.poetry/env && poetry build && /venv/bin/pip install dist/*.whl"

pyproject.toml

[tool.poetry]
name = "cuppa-seeder"
version = "0.1.0"
description = "Python backend for the census app"
authors = ["xxxx <xxxo@xxx.xxx>"]

[tool.poetry.dependencies]
python = "~3.7.4"
requests = "^2.23.0"
psycopg2-binary = "^2.8.4"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
user1315621
  • 3,044
  • 9
  • 42
  • 86
  • Run "file /app/.venv/bin/python" and report back the results – Dr. Snoopy Mar 13 '20 at 23:24
  • Including the entire `Dockerfile` in the question would be helpful, along with describing how you're running the container. Typical style is to not use a virtual environment inside a Docker image, which already is isolated from the host-system Python, and just running `pip install` and `python ...` can simplify things. – David Maze Mar 13 '20 at 23:53
  • Actually it doesn't print anything. It just stucks on that command without returning – user1315621 Mar 13 '20 at 23:53
  • 2
    Three of the four answers to the question you link to recommend disabling Poetry's virtual environment setup; have you tried that? Are you on a MacOS or Windows host, and if so, does adding `.venv` to a [`.dockerignore` file](https://docs.docker.com/engine/reference/builder/#dockerignore-file) help (preventing you from using a wrong-architecture host virtual environment)? – David Maze Mar 14 '20 at 04:48
  • It was the .venv directory. If you want to post and answer I'll confirm it. – user1315621 Mar 17 '20 at 21:21

0 Answers0