【问题标题】:file not found error when setting the environment variable in docker compose yml file在 docker compose yml 文件中设置环境变量时找不到文件错误
【发布时间】:2019-02-11 04:53:56
【问题描述】:

我正在我的 docker-compose.yml 文件中设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量。这是我的 docker-compose.yml 文件的结构:

version: "2"

services:

  server:
    container_name: server

    environment:
        - GOOGLE_APPLICATION_CREDENTIALS=/dir1/dir2/file1.json

我的 JSON 文件位于上述目录中。在我的 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()

当我在上面执行时,它会抛出 google.auth.exceptions.DefaultCredentialsError: File /dir1/dir2/file1.json was not found. 的错误

我无法理解为什么当它存在于正确的目录中时它无法找到 JSON。

【问题讨论】:

    标签: python docker docker-compose environment-variables google-cloud-speech


    【解决方案1】:

    确保将 /dir1/dir2/file1.json 添加到 Docker 映像或将其作为卷挂载。将文件存在于主机上的该位置是不够的。

    【讨论】:

    • 如何将文件添加到我的 docker 镜像中?我是 Docker 新手,所以不确定
    • 所以我必须在 mt Dockerfile 中添加 COPY /dir1/dir2/file1.json dire/ 才能将 json 添加到我的 WORKDIR 中的 dire 目录中?然后我在 docker-compose.yml 中指定什么目录?
    猜你喜欢
    • 2022-06-24
    • 2020-02-25
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    • 2017-06-16
    • 2015-05-29
    相关资源
    最近更新 更多