Home > Blockchain >  How to work with the files from a docker container
How to work with the files from a docker container

Time:11-30

I need to work with all the files from a docker container, my approach is to copy all the list of files from the container to my host.

I'm using the next docker commands, for example with the postgres image:

docker create -ti --name dummy_1 postgres bash
docker cp dummy_1:/. Documents/docker/dockerOne

With this I have all the container folders and files in my host.

And then the idea is to transverse all the files with the java API, and work with them and finally delete the files and folders from local, but I would like to know if is it a better approach, maybe with Java and access directly to the container files, instead of create a local copy of the container files in my host.

Any ideas?

CodePudding user response:

You can build a small server app inside your docker container which feeds you the information you need at an exposed port. Thats how i would have done it.

CodePudding user response:

Maybe I don't understand the question, but you can mount a volume when you run, not create the container

docker run -v /host/path:/container/path your_container

Any code in the container (e.g. Java) that modifies files at /container/path will be reflected on the host, and not need to be copied back in/out. Similarly, any modifications on the host filesystem will be seen in the container.

I don't think I can implement an API in the docker container

Yes you can. You bind a TCP port using -p flag

  • Related