在 /app 檔案夾中,我有一個 Google Cloud 憑據檔案ocviam-dev-201b2db30d36.json
> docker exec -ti 9ac6de5f24586320ac41c6e2de9895f03ca87874745257642214852e755a4a99 bash
root@9ac6de5f2458:/# cd /app/
root@9ac6de5f2458:/app# ll
total 252
drwxr-xr-x 2 root root 4096 Apr 20 13:42 ./
drwxr-xr-x 1 root root 4096 Apr 20 13:44 ../
-rwxr-xr-x 1 root root 10875 Apr 20 12:29 function.R*
-rwxr-xr-x 1 root root 284 Apr 20 09:40 gfs_data_temp12042022.csv*
-rwxr-xr-x 1 root root 183311 Apr 12 07:33 gfs_data_temp_FULL.csv*
-rwxr-xr-x 1 root root 2331 Mar 22 15:49 ocviam-dev-201b2db30d36.json*
-rwxr-xr-x 1 root root 3355 Apr 20 12:34 plumber.R*
-rwxr-xr-x 1 root root 33467 Apr 13 09:39 .RData*
-rwxr-xr-x 1 root root 405 Apr 13 09:39 .Rhistory*
但是當我使用變數和值運行docker run -e選項時,我得到一個錯誤:GOOGLE_APPLICATION_CREDENTIALS/app/ocviam-dev-201b2db30d36.json
docker run --rm -it -p 80:8000 app1 -e GOOGLE_APPLICATION_CREDENTIALS=ocviam-dev-201b2db30d36.json
>>
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> pr <- plumber::plumb(rev(commandArgs())[1]); args <- list(host = '0.0.0.0', port = 8000); if (packageVersion('plumber') >= '1.0.0') { pr$setDocs(TRUE) } else { args$swagger <- TRUE }; do.call(pr$run, args)
Error in plumber::plumb(rev(commandArgs())[1]) :
File does not exist: GOOGLE_APPLICATION_CREDENTIALS=ocviam-dev-201b2db30d36.json
Execution halted
(base) PS C:\Chantiers\repos\gcp-gfs-weather> docker run --rm -it -p 80:8000 app1 -e GOOGLE_APPLICATION_CREDENTIALS=/app/ocviam-dev-201b2db30d36.json
>>
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> pr <- plumber::plumb(rev(commandArgs())[1]); args <- list(host = '0.0.0.0', port = 8000); if (packageVersion('plumber') >= '1.0.0') { pr$setDocs(TRUE) } else { args$swagger <- TRUE }; do.call(pr$run, args)
Error in plumber::plumb(rev(commandArgs())[1]) :
File does not exist: GOOGLE_APPLICATION_CREDENTIALS=/app/ocviam-dev-201b2db30d36.json
Execution halted
是語法問題嗎?
謝謝。
uj5u.com熱心網友回復:
docker run命令中的-e選項用于將環境變數作為或傳遞。如果您需要傳遞其中存盤了環境變數的檔案,請創建一個檔案(例如“env.list”),其內容如下:-e MYVAR1--env MYVAR2=foo
變數 1=值 1
變數 2 =值 2
發布可以運行docker run --env-file env.list 的帖子,它將設定檔案中提到的所有環境變數。
如果您的初衷是使用 JSON 對您的 Google Cloud 專案進行身份驗證,則應使用gcloud auth進行身份驗證:
gcloud auth activate-service-account [ACCOUNT] --key-file=KEY_FILE --project=PROJECT_NAME
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/460320.html
標籤:码头工人
