0

We are creating openSource tool “Scanner” which scans files within specific directory after user gives path to that folder/directory as input (locally)

It’s working perfectly but now we need to containerize it using Docker and the issue is this that we cannot bind the whole root/system while building image (because in most of the cases, it can be very large and will also contains many unnecessary files and folders etc) but we also wanna access files within that specific folder for which user will provide “Scanner” with folder path (locally) and that will be outside the container

So do you have any idea that how it can be done and we can access the files and folder from outside the container and use them at run time

  • Without special setup by the user launching the container, a container process can't access host directories at all; when it does, it uses a container-private filesystem path which is not necessarily the same as the host path. If the major goal of your application is to scan a large number of host-filesystem files, isolating it from the host filesystem in a Docker container might not be the ideal packaging approach. – David Maze Aug 11 '21 at 10:48

1 Answers1

0

You can set your app to just scan current folder inside the image.

When running a container from the image with docker run ..., if you set the -w flag you indicate the container de default working directory.

Along wit a -v flag you can mount a directory from the host into the container working directory (the one you indicate with -w).

You can see an example of this in the Maven Official image, and one of its Dockerfiles

$ docker run ... -v /my_files_to_compile:/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn clean install

my_files_to_compile is the host directory where java source files are. /usr/src/mymaven is where the host directory will be mounted and also the path/working directory where the container is going to be executed

usuario
  • 2,132
  • 1
  • 10
  • 26