Reading input files with docker

后端 未结 1 1641
北海茫月
北海茫月 2021-01-13 19:08

I\'m writting a C++ program that is run as follows:

./program data_file config_file

And I want to use docker with it. I\'ve written the fol

相关标签:
1条回答
  • 2021-01-13 19:49

    You can use volume mechanism for mount a host directory to the container.

    Create file1.txt and file2.txt files in some directory in the host machine. For example we are creating files in the /var/dir1/ directory.
    Your working dir in the docker container is /program.

    So when you are running docker you should mount this host directory to container using -v flag

    docker run -v /var/dir1/:/program test file1.txt file2.txt
    

    Oh, I know why we have problem.

    When I am mounting the host directory to working dir I am actually deleting all created files inside container from it working dir including the ./program binary file. So the docker run command is failed.
    therefore we not must mount working directory. We can mount subdirectory of working directory for example.

     docker run -v /var/dir1/:/program/dir test dir/file1.txt dir/file2.txt 
    

    It works for me!

    0 讨论(0)
提交回复
热议问题