I'm writting a C++ program, and want to use Docker on it. The Dockerfile
looks like the following:
FROM gcc:7.2.0
ENV MYP /repo
WORKDIR ${MYP}
COPY . ${MYP}
RUN /bin/sh -c 'make'
ENTRYPOINT ["./program"]
CMD ["file1", "file2"]
This program needs two input files (file1 and file2) and is built and executed with as follows:
docker build -t image .
docker run -v /home/user/tmp/:/repo/dir image dir/file1 dir/file2
These input files are located in the host in /home/user/tmp/
. In the original repository (repo/
), the executable is located in its root directory, and the output file generated is saved in the same folder (i.e. they look like repo/program
and repo/results.md
).
When I run the above docker run
command, I can see from the standard output that the executable is reading correctly the input files and generating the expected results. However, I hoped the written output file (generated by the program with std::ofstream
) to be also saved in the mounted directory /home/user/tmp/
, but its not.
How can I access this file? Is there a straightforward way to get it using the docker volume mechanism?
Docker version is 18.04.0-ce, build 3d479c0af6.
EDIT
The relevant code regarding how the program saves the output file result.md
is the following:
std::string filename ("result.md"); // in the actual code this name is not hard-coded and depends on intput, but it will not include / chars
std::ofstream output_file;
output_file.open(filename.data(), std::ios::out);
output_file << some_data << etc << std::endl;
...
output_file.close();
In practice, the program is run as program file1 file2
, and the output will be saved in the working directory, not matter if its the same where program
is placed or not.
docker run -v /home/user/tmp/:/repo/dir image bash
Are there any errors indocker logs
?bash
), it responds a similar error message. I'm going to look into the logs, but cannot tell you right now becausedocker ps
does not return container names and have never useddocker log
before. Any way, when I run the command in the post, from the standard output I would say that the binary is being executed as expected.docker run -ti -v /home/user/tmp/:/repo/dir image dir/file1 dir/file2 bash
the program will also return an error indicating that there are more arguments than expected. Withoutbash
the program runs well, but cannot see the output files with-ti
. @zero298 I just come to see the logs and looks fine.