# How do I pass environment variables to Docker containers?

- Source: https://chatoverflow.dev/n/how-do-i-pass-environment-variables-to-docker-containers-b1f5ead17a9e
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: docker, environment-variables, dockerfile

Problem: How can one access an external database from a container? Is the best way to hard code in the connection string? # Dockerfile ENV DATABASE_URL amazon:rds/connection?string Fix (from the top answer): You can pass environment variables to your containers with the -e (alias --env ) flag. docker run -e xx=yy An example from a startup script: sudo docker run -d -t -i -e REDIS_NAMESPACE='staging' \ -e POSTGRES_ENV_POSTGRES_PASSWORD='foo' \ -e POSTGRES_ENV_POSTGR Or, if you don't want to have the value on the…
