Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[BUG] pre_start no longer inherits its parent environment

Aperta
#14,287 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@ndeloof ci sta già lavorando.

Dal 7/10/2026.

  • #14293 di @ndeloof — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

kind/bug
Description

In docker compose, I have a pre_start clause to run an alembic command. before docker compose v5.6.0 it worked fine, once I upgraded my version I started having issues

  File "//alembic/env.py", line 104, in get_database_uri
    raise RuntimeError(f"{DATABASE_URI_VARIABLE} is not set in the environment.")
RuntimeError: DATABASE_URI is not set in the environment.

I ran docker compose config and got

(...)
  src:
    restart: always
    pre_start:
      - command:
          - alembic
          - upgrade
          - head
        env_file:
          - path: {CORRECT_PATH_TO_ENV_FILE}
        extra_hosts:
          - host.docker.internal=host-gateway
        networks:
          default: null
    environment:
      DATABASE_URI: (...)

But the environment values are not recognized inside the pre_start container. This is the result of env in the pre_start container:

HOSTNAME=7df048caff72
HOME=/root
PYTHONUNBUFFERED=1
GPG_KEY=7169605F62C751356D054A26A821E680E5FA6305
PYTHON_SHA256=f4b1bfb3c79b5bb11b8d228a12504163b4c0dab4d679828d8f5f26b6cb6ab35d
PYTHONDONTWRITEBYTECODE=1
PATH=/opt/venv/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PYTHON_VERSION=3.13.16
PWD=/
Steps To Reproduce
  1. with docker version 29.8.2, Docker Compose version v5.6.0
  2. docker compose config
services:
  database:
    image: postgres:15-alpine
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}" ]
      interval: 10s
      retries: 5
      start_period: 30s
      timeout: 10s
    volumes:
      - database:/var/lib/postgresql/data
    env_file:
      - .env
    restart: always

  src:
    build:
      context: .
      secrets:
        - url_lib_common_py
    volumes:
      - ./logs:/src/logs
      - ./alembic:/alembic
      - config:/root/.config
    extra_hosts:
      - "host.docker.internal:host-gateway"
    env_file:
      - .env
    depends_on:
      database:
        condition: service_healthy
        restart: true
    pre_start:
      - command: alembic upgrade head
    restart: always

secrets:
  url_lib_common_py:
    environment: URL_LIB_COMMON_PY


volumes:
  database:
  credentials:
  config:
  1. Run docker compose up
  2. Get:
(...)
  File "//alembic/env.py", line 104, in get_database_uri
    raise RuntimeError(f"{DATABASE_URI_VARIABLE} is not set in the environment.")
RuntimeError: DATABASE_URI is not set in the environment.
Compose Version
v5.6.0
Docker Environment
29.8.2
Anything else?

No response

Lingua principale
Go
Stelle
38.3k
Fork
5.8k
Merge medio
2g 17h
PR unite (30g)
47

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di docker/compose

Tutte le issue di docker/compose

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.