How to set environment variable into docker container using docker-compose

久未见 提交于 2020-01-04 13:11:19

问题


I want to set credentials to use Google Translate Api Client so I have to set environment variable GOOGLE_APPLICATION_CREDENTIALS that value is path to credential file (from Google Cloud).

When I have been used docker build and docker run it was pretty easy.

I have been used docker run --env GOOGLE_APPLICATION_CREDENTIALS=/usr/src/app/CryptoTraderBot-901d31d199ce.json and environment variable has been set.

More difficult things come when I tried to set it in docker-compose. I have to use docker-compose because I need few containers so it is only way to achieve this.

Based on Docker compose environment variables documentation I created my docker-compose.yml file that looks like this:

version: "3"
services:
redis:
  image: redis:4-alpine
crypto-bot:
  build: .
  depends_on:
    - redis
  environment:
    - GOOGLE_APPLICATION_CREDENTIALS = /usr/src/app/CryptoTraderBot-901d31d199ce.json

I also have been tried multiple combination of path to .json file but none of this has been worked properly.

Have you got any idea how can I set it properly ?


回答1:


While creating this question I have been resolve this problem in a funny and easy way but I have been thought that I post answer to help someone in the future with similiar problem.

All you have to do is remove " " (space) next = sign so two last lines of docker-compose.yml should looks like this: environment: - GOOGLE_APPLICATION_CREDENTIALS=/usr/src/app/CryptoTraderBot-901d31d199ce.json



来源:https://stackoverflow.com/questions/50238621/how-to-set-environment-variable-into-docker-container-using-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!