Reputation: 1459
I have Java app writing some output files to the user home directory. I built a docker image for this Java app and ran the docker container. I also added logs to my program to see where the file gets saved.
Writing the metadata to the file path /root/39fd75837c864a68a8db42442d4401fa.txt
When I run docker run -it imageId bash
and tried to access the above file in the container but was unable to find it.
Where do these files get saved and how to access those files inside the docker container?
Upvotes: 1
Views: 2438
Reputation: 1767
Every time you run docker run
command, docker creates a new container. In order to be able to access your files you either need access the same container or persist the files across containers on a volume.
If you run a container with docker run -it imageId bash
command, the container will shut down as soon as you exit from it. Therefore, consider running it as daemon (-d
option) - in this case container will keep running once you exit from it.
Second option would be to start the same container and attach to it with exec command:
docker start my_container
Attaching to the running container with exec command:
docker exec -it my_container bash
Or you can simply copy the files from running container, using docker cp
The third option is to attach a volume persisting the files:
docker run -v /app/data:/data imageId
Upvotes: 1