[英]file not found error when setting the environment variable in docker compose yml file
I am setting the GOOGLE_APPLICATION_CREDENTIALS environment variable from within my docker-compose.yml file. 我正在从docker-compose.yml文件中设置GOOGLE_APPLICATION_CREDENTIALS环境变量。 This is the structure of my docker-compose.yml file:
这是我的docker-compose.yml文件的结构:
version: "2"
services:
server:
container_name: server
environment:
- GOOGLE_APPLICATION_CREDENTIALS=/dir1/dir2/file1.json
My JSON file is present in the above directory. 我的JSON文件位于上述目录中。 From my python code, which is also run as part of Docker container, I am using Google Speech API like this:
从我的python代码(也作为Docker容器的一部分运行),我正在使用Google Speech API,如下所示:
import io
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
#take speech wav file and turn it into text. return text
def transcribe_file(speech_file):
"""Transcribe the given audio file."""
client = speech.SpeechClient()
When I execute above it throws error that google.auth.exceptions.DefaultCredentialsError: File /dir1/dir2/file1.json was not found.
当我在上面执行时,抛出
google.auth.exceptions.DefaultCredentialsError: File /dir1/dir2/file1.json was not found.
错误: google.auth.exceptions.DefaultCredentialsError: File /dir1/dir2/file1.json was not found.
I am unable to understand why it is not able to find the JSON when it is present in the correct directory. 我无法理解为什么正确的目录中存在JSON时无法找到JSON。
Make sure that you're adding /dir1/dir2/file1.json
to your Docker image or mounting it as a volume. 确保将
/dir1/dir2/file1.json
添加到Docker映像中或将其作为卷安装。 Having the file present at that location on the host isn't sufficient. 仅在主机上的该位置提供文件是不够的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.