How do I pass environment variables to Docker containers?

前端 未结 14 1507
独厮守ぢ
独厮守ぢ 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:26

    You can pass using -e parameters with docker run .. command as mentioned here and as mentioned by @errata.

    However, the possible downside of this approach is that your credentials will be displayed in the process listing, where you run it.

    To make it more secure, you may write your credentials in a configuration file and do docker run with --env-file as mentioned here. Then you can control the access of that config file so that others having access to that machine wouldn't see your credentials.

提交回复
热议问题