简体   繁体   中英

How to mount .pgpass file in docker?

I have test_main_file.py and dockerfile in my project. There is a line in test_main_file.py

redshift= open(os.environ['Home'] + '/.pgpass','r').readline()

which is nothing but redshift database information.

Now I am running above .py file in docker but I am getting following error:

redshift = open(os.environ['HOME'] + '/.pgpass', 'r').readline() 
              IsADirectoryError: [Errno 21] Is a directory: '/root/.pgpass'

My docker command is:

docker run --volume ~/.aws:/root/.aws --volume ~/Users/mmarvania/.pgpass:/root/.pgpass docker5

FYI: my .pgpass file is in /Users/mmarvania/ directory in my mac.

If it is a file, map the folder which contains .pgpass file to a folder inside the container. Then access the file inside that folder. docker run --volume ~/.aws:/root/.aws --volume ~/Users/mmarvania:/root/config docker5 The access the file like this: redshift = open(os.environ['HOME'] + '/config/.pgpass', 'r').readline()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM