dg1996
dg1996

Reputation: 25

Save Docker container file to host filesystem

I have a Docker container that runs a Python app and generates a file as a result. I would like to persist this file in my local file system and not to lose it at the end of the container's execution.

After reading other posts and documentation of volumes and data storage in Docker I have tried to solve it in different ways like:

Using a volume (created before):

 docker run --name my_container -v my_volume:/container_file_path my_container

I'm missing something here because I understand that I'm not referencing the host's route at any time.

Or directly referencing host path and container path (with this option I also got some problems with absolute or relative paths usage):

docker run --name my_container -v host_path:container_file_path my_container

I also tried some other "variants" of the commands above (--mount instead of -v, changing target/source values, etc.) but I couldn't get it to work.

I'm using Windows Subsystem for Linux (WSL), which I've read may be the cause of the problem.

Could you guide me in what I am doing wrong? Thanks!

Upvotes: 1

Views: 244

Answers (1)

Christian Fosli
Christian Fosli

Reputation: 1847

The second option with the bind-mount volume sounds good to me. You do need to use absolute paths, but you can use e.g. $(pwd) to make it simpler.

Upvotes: 2

Related Questions