How do I pass environment variables to Docker containers?

前端 未结 14 1399
独厮守ぢ
独厮守ぢ 2020-11-22 11:15

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?

# Dockerfil         


        
14条回答
  •  醉梦人生
    2020-11-22 11:31

    docker run --rm -it --env-file <(bash -c 'env | grep ') Is a way to grep the data stored within a .env and pass them to Docker, without anything being stored unsecurely (so you can't just look at docker history and grab keys.

    Say you have a load of AWS stuff in your .env like so:

    AWS_ACCESS_KEY: xxxxxxx
    AWS_SECRET: xxxxxx
    AWS_REGION: xxxxxx
    

    running docker with ```docker run --rm -it --env-file <(bash -c 'env | grep AWS_') will grab it all and pass it securely to be accessible from within the container.

提交回复
热议问题