Docker Community Forums

Share and learn in the Docker community.

Read file of other container

How can I read file of one container from another container.

Since you didn’t share any details the answer is: it depends.

Mind sharing more details about your situation? Are you running plain docker container with the cli or docker-compose? Or swarm services? Is the file you want to access on a volume inside the other container?

Container 1 : I have created one web application in .Net core, Which generates one file, contains server configuration details.
Container 2 : I have created web API in .Net Core, which reads configuration details from file generated by web application in container 1.
Once I will get path of Configuration details, I will pass it using appsettings.json file to read.
But I don’t know how to read file from container 1 as I am new to docker.
I have pushed web application and api to docker hub.

Could you be so kind to address these questions as well, as they are important to answer your question properly.

I am running plain Docker Container.

This one is still unanswered, but for now I assume that it is the case.

You have severall possible solutions:

  • mount all volumes of another container in a created container: docker run --volumes-from=${source container}

  • use the same host folder in both containers: docker run -v /opt/shared/folder:/target/folder/in/container.

And of course you can use volumes, which can either be backed by local bind-mounts or remote shares.

1 Like