How do I pass environment variables to Docker containers?

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

    Using jq to convert the env to JSON:

    env_as_json=`jq -c -n env`
    docker run -e HOST_ENV="$env_as_json" 
    

    this requires jq version 1.6 or newer

    this pust the host env as json, essentially like so in Dockerfile:

    ENV HOST_ENV  (all env from the host as json)
    

提交回复
热议问题