admin管理员组

文章数量:1310441

Recently I was optimizing a Python-based Docker image and ran into an issue where running pip install poetry after I copied my project files caused the image to not start properly and eventually crash with an error code.

My initial Dockerfile started like this:

FROM python:3.13-bookworm

ARG POETRY_VERSION=2.0.1

WORKDIR /app

RUN touch README.md
COPY poetry.lock pyproject.toml ./
COPY mymodule ./mymodule

RUN pip install poetry==$POETRY_VERSION
RUN poetry install

The image would build successfully but when I ran it, I would get the following:

Attaching to signal-api-1, signal-bot-1
signal-api-1  | + set -e
signal-api-1  | + [ -z /home/.local/share/signal-cli ]
signal-api-1  | + usermod -u 1000 signal-api
signal-api-1  | usermod: no changes
signal-api-1  | + groupmod -o -g 1000 signal-api
signal-api-1  | + chown 1000:1000 -R /home/.local/share/signal-cli
signal-api-1  | + cat
signal-api-1  | + cap_prefix=-cap_
signal-api-1  | + cat /proc/sys/kernel/cap_last_cap
signal-api-1  | + seq -s ,-cap_ 0 40
signal-api-1  | + caps=-cap_0,-cap_1,-cap_2,-cap_3,-cap_4,-cap_5,-cap_6,-cap_7,-cap_8,-cap_9,-cap_10,-cap_11,-cap_12,-cap_13,-cap_14,-cap_15,-cap_16,-cap_17,-cap_18,-cap_19,-cap_20,-cap_21,-cap_22,-cap_23,-cap_24,-cap_25,-cap_26,-cap_27,-cap_28,-cap_29,-cap_30,-cap_31,-cap_32,-cap_33,-cap_34,-cap_35,-cap_36,-cap_37,-cap_38,-cap_39,-cap_40
signal-api-1  | + [ json-rpc = json-rpc ]
signal-api-1  | + /usr/bin/jsonrpc2-helper
signal-api-1  | time="2025-01-31T12:14:27Z" level=info msg="Updated jsonrpc2.yml"
signal-api-1  | + [ -n  ]
signal-api-1  | + service supervisor start
signal-api-1  | Starting supervisor: 
signal-api-1 exited with code 1
signal-bot-1 exited with code 144

Making the one line change of moving pip install poetry above the COPY directives:

FROM python:3.13-bookworm

ARG POETRY_VERSION=2.0.1

WORKDIR /app

RUN pip install poetry==$POETRY_VERSION

RUN touch README.md
COPY poetry.lock pyproject.toml ./
COPY mymodule ./mymodule

RUN poetry install

Everything works fine:

Attaching to signal-api-1, signal-bot-1
signal-api-1  | + set -e
signal-api-1  | + [ -z /home/.local/share/signal-cli ]
signal-api-1  | + usermod -u 1000 signal-api
signal-api-1  | usermod: no changes
signal-api-1  | + groupmod -o -g 1000 signal-api
signal-api-1  | + chown 1000:1000 -R /home/.local/share/signal-cli
signal-api-1  | + cat
signal-api-1  | + cap_prefix=-cap_
signal-api-1  | + cat /proc/sys/kernel/cap_last_cap
signal-api-1  | + seq -s ,-cap_ 0 40
signal-api-1  | + caps=-cap_0,-cap_1,-cap_2,-cap_3,-cap_4,-cap_5,-cap_6,-cap_7,-cap_8,-cap_9,-cap_10,-cap_11,-cap_12,-cap_13,-cap_14,-cap_15,-cap_16,-cap_17,-cap_18,-cap_19,-cap_20,-cap_21,-cap_22,-cap_23,-cap_24,-cap_25,-cap_26,-cap_27,-cap_28,-cap_29,-cap_30,-cap_31,-cap_32,-cap_33,-cap_34,-cap_35,-cap_36,-cap_37,-cap_38,-cap_39,-cap_40
signal-api-1  | + [ json-rpc = json-rpc ]
signal-api-1  | + /usr/bin/jsonrpc2-helper
signal-api-1  | time="2025-01-31T12:32:28Z" level=info msg="Updated jsonrpc2.yml"
signal-api-1  | + [ -n  ]
signal-api-1  | + service supervisor start
signal-api-1  | Unlinking stale socket /var/run/supervisor.sock
signal-api-1  | Starting supervisor:  ERROR.
signal-api-1  | + supervisorctl start all
signal-api-1  | + hostname -I
signal-api-1  | + awk {print $1}
signal-api-1  | + export HOST_IP=192.168.32.2
signal-api-1  | + exec setpriv --reuid=1000 --regid=1000 --init-groups --inh-caps=-cap_0,-cap_1,-cap_2,-cap_3,-cap_4,-cap_5,-cap_6,-cap_7,-cap_8,-cap_9,-cap_10,-cap_11,-cap_12,-cap_13,-cap_14,-cap_15,-cap_16,-cap_17,-cap_18,-cap_19,-cap_20,-cap_21,-cap_22,-cap_23,-cap_24,-cap_25,-cap_26,-cap_27,-cap_28,-cap_29,-cap_30,-cap_31,-cap_32,-cap_33,-cap_34,-cap_35,-cap_36,-cap_37,-cap_38,-cap_39,-cap_40 signal-cli-rest-api -signal-cli-config=/home/.local/share/signal-cli
signal-api-1  | time="2025-01-31T12:32:29Z" level=info msg="Started Signal Messenger REST API"
signal-bot-1  | WARNING:root:[Bot] Could not initialize Redis. In-memory storage will be used. Restarting will delete the storage!
signal-api-1  | [GIN] 2025/01/31 - 12:32:33 | 200 |  1.303127316s |    192.168.32.3 | GET      "/v1/groups/+REDACTED"

I am happy that I found a solution to my issue, however I would like some insight into why this was an error to begin with. I tried various configurations for my Dockerfile and the only fix was to run pip install poetry before copying files.

EDIT:

Please note that my Dockerfile is building the signal-bot image. The initial error from the build actually comes from a pre-built image from so why it is affected by my build in the first place is also a mystery.

本文标签: pythonDocker image failing to start when running pip install after copying filesStack Overflow