How do I pass environment variables to Docker containers?

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

    There is a nice hack how to pipe host machine environment variables to a docker container:

    env > env_file && docker run --env-file env_file image_name
    

    Use this technique very carefully, because env > env_file will dump ALL host machine ENV variables to env_file and make them accessible in the running container.

提交回复
热议问题