簡體   English   中英

在docker compose yml文件中設置環境變量時找不到文件錯誤

[英]file not found error when setting the environment variable in docker compose yml file

我正在從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.錯誤: google.auth.exceptions.DefaultCredentialsError: File /dir1/dir2/file1.json was not found.

我無法理解為什么正確的目錄中存在JSON時無法找到JSON。

確保將/dir1/dir2/file1.json添加到Docker映像中或將其作為卷安裝。 僅在主機上的該位置提供文件是不夠的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM