docker / docker/cli

Support for docker secrets exported as environment variables

Open
#6,678 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/feature status/0-triage
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Docker secrets are intentionally mounted into containers as files under /run/secrets/, which is a secure default. However, many applications and frameworks expect configuration via environment variables rather than files. As a result, users frequently resort to workarounds like:

entrypoint: >
  sh -c "export API_KEY=$(cat /run/secrets/api_key) && exec myapp"

This pattern is widely used and effectively gives the container an environment variable anyway — just with more boilerplate and no additional security compared to a built-in feature.

Providing an optional way to export a secret as an environment variable would significantly improve ergonomics in cases where this pattern is required.

Kubernetes, for example, supports this functionality:
https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#define-a-container-environment-variable-with-data-from-a-single-secret

Docker could offer an equivalent mechanism with a syntax like:

secrets:
  - secret: api_key
    as_env: APP_API_KEY

This would avoid shell-based workarounds while keeping the current file-mount behavior as the default.

For example, in co-op cloud, which packages open source applications using docker swarm, there are many applications which require secrets as environment variables and this would be a great improvement on app packaging.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how the Docker CLI parses and forwards secret definitions, then determine whether environment-variable export belongs in this repository or in Docker's engine or Swarm implementation. Done requires an agreed configuration syntax, clarified behavior alongside the existing file mount, and tests covering the proposed option.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli, devops
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.