in /app folder, I have a Google Cloud credential file 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*
But when I run docker run -e
option with GOOGLE_APPLICATION_CREDENTIALS
variable and /app/ocviam-dev-201b2db30d36.json
value, I get an error:
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
Is it a problem of syntax?
Thanks.
CodePudding user response:
The -e
option in docker run commands is for passing environment variables as -e MYVAR1
or --env MYVAR2=foo
. If you need to pass a file which has the environment variables stored in them, create a file (say "env.list") with contents like this:
Variable1=Value1
Variable2=Value2
Post which you can run docker run --env-file env.list which will set all the environment variables mentioned in the file.
If your original intention was to authenticate to your Google Cloud Project using the JSON, you should do so using gcloud auth:
gcloud auth activate-service-account [ACCOUNT] --key-file=KEY_FILE --project=PROJECT_NAME