I want to capture the content of file which is located in the host os (linus) into a variable from the Docker container using a python script
Can I do this
FILE="/home/test/file.txt"
#open the file for read-only
fd = os.open(FILE,os.O_RDONLY)
content = os.read(fd,12)
print content
ended up with this error
OSError: [Errno 2] No such file or directory: '/home/test/file.txt'
Please suggest a way if I am doing it wrong
mount the volume where the file is located into a directory in your docker container
you do this by using the -v
flag in docker
for example:
docker run -v <HOST_FOLDER>:/data <IMAGE>
that will mount to the folder data
on the root of your container ( /data
)
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.