Skip to content

Secrets file not detected on startup #1228

@r-xyz

Description

@r-xyz

Hi all,

I am experiencing an issue trying to use Docker Secrets with latest postgres library (alpine), using Docker Compose.

From Official Page

Docker Secrets

As an alternative to passing sensitive information via environment variables, _FILE may be appended to some of the previously listed environment variables, causing the initialization script to load the values for those variables from files present in the container. In particular, this can be used to load passwords from Docker secrets stored in /run/secrets/<secret_name> files. For example:
$ docker run --name some-postgres -e POSTGRES_PASSWORD_FILE=/run/secrets/postgres-passwd -d postgres
Currently, this is only supported for POSTGRES_INITDB_ARGS, POSTGRES_PASSWORD, POSTGRES_USER, and POSTGRES_DB.

Expected behaviour

Secret shall correctly be loaded from path in POSTGRES_PASSWORD_FILE (/run/secrets/POSTGRES_PASSWORD).

Current behaviour

$ docker compose up fails with

postgres  | /usr/local/bin/docker-entrypoint.sh: line 21: "/run/secrets/POSTGRES_PASSWORD": No such file or directory

Nonetheless, the file is present and contains the password:

$ docker compose run --user 10100 postgres cat /run/secrets/POSTGRES_PASSWORD
MYPASSWORD

Steps to reproduce

compose.yaml:

services:
  postgres:
    container_name: postgres
    image: "postgres:16.2-alpine"
    volumes:
      - "./data:/var/lib/postgresql/data"
    environment:
      - POSTGRES_USER="postgres"
      - POSTGRES_PASSWORD_FILE="/run/secrets/POSTGRES_PASSWORD"
    user: "10100"
    secrets:
      - postgres-password
    restart: unless-stopped
secrets:
  POSTGRES_PASSWORD:
    file: "./.secrets/POSTGRES_PASSWORD.txt"

.secrets/POSTGRES_PASSWORD.txt:

MYPASSWORD

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions