I'm new to Docker, and it's unclear how to 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
dockerdockerfileenvironment-variables
I'm new to Docker, and it's unclear how to 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
Best Solution
You can pass environment variables to your containers with the
-eflag.An example from a startup script:
Or, if you don't want to have the value on the command-line where it will be displayed by
ps, etc.,-ecan pull in the value from the current environment if you just give it without the=:If you have many environment variables and especially if they're meant to be secret, you can use an env-file: