Transfer files to host machine -- or other containers-- on docker run completion


I am new to docker and am looking for a way to export json report files from docker automatically to my host machine or to another docker container. I would like this to happen from within the container if at all possible so that when I run the container it will send the report back to my machine

Thanks for any/all help!

I think the parts “on docker run completion” and “happen from within the container” complicate things. What about just making a specific folder on your host machine always available to the container(s)? Then it’s up to your container(s) when to use that.

That is what “bind mounts” are for, but it’s not something that can be setup from within the container, unless you grant it specific rights. It’s much easier to configure it when starting the container; see Use bind mounts in the Getting Started.

If the JSON output is only needed by other containers, not on the host machine directly, then Docker “named volumes” can also be shared across containers. See Persist the DB in the Getting Started.

1 Like