Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[BUG] pre_start no longer inherits its parent environment

Đã đóng
#14,287 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@ndeloof đang làm issue này rồi.

Từ ngày 7/10/2026.

  • #14293 của @ndeloof — đã merge

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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

Ngôn ngữ chính
Go
Star
38.4k
Fork
5.9k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
73

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của docker/compose

Tất cả issue của docker/compose

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.