user1298426
user1298426

Reputation: 3717

How to access file from host directory of docker container?

I have this part of my python code which iterates through the folder and add file names to the list.

base_path = D:/tests/resources

for file in glob.glob(f'{base_path}/eox/data/eur/*.txt'):
    lst.append(file)

Now I have the docker images where I assume it should do the same thing after running this docker command.

docker run -i --rm -v D:/tests/resources:/tmp/output dockerimg:latest prepare --base_path D:/tests/resources

but somehow the list is empty even though D:/tests/resources have txt files in it. Is it because the volume is not mounted correctly?

Upvotes: 0

Views: 637

Answers (1)

atline
atline

Reputation: 31584

The syntax for bind mount is:

-v source_path_in_host:destination_path_in_container

This means for -v D:/tests/resources:/tmp/output, the folder in host's D:/tests/resources will be mapped into /tmp/output in container.

Additional, prepare --base_path D:/tests/resources in fact won't be run on host, but will be executed in container. So, for the script prepare, it should accept the --base_path as /tmp/output for command input, not D:/tests/resources.

Upvotes: 1

Related Questions