title: How to access to an output file with Docker
body: <p>I'm writting a C++ program, and want to use Docker on it. The <code>Dockerfile</code> looks like the following:</p>
  
  <pre><code>FROM gcc:7.2.0
  ENV MYP /repo
  WORKDIR ${MYP}
  COPY . ${MYP}
  
  RUN /bin/sh -c 'make'
  ENTRYPOINT ["./program"]
  CMD ["file1", "file2"]
  </code></pre>
  
  <p>This program needs two input files (<em>file1</em> and <em>file2</em>) and is built and executed with as follows:</p>
  
  <pre><code>docker build -t image .
  docker run -v /home/user/tmp/:/repo/dir image dir/file1 dir/file2
  </code></pre>
  
  <p>These input files are located in the host in <code>/home/user/tmp/</code>. In the original repository (<code>repo/</code>), the executable is located in its root directory, and the output file generated is saved in the same folder (<em>i.e.</em> they look like <code>repo/program</code> and <code>repo/results.md</code>).</p>
  
  <p>When I run the above <code>docker run</code> 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 <code>std::ofstream</code>) to be also saved in the mounted directory <code>/home/user/tmp/</code>, but its not.</p>
  
  <p>How can I access this file? Is there a straightforward way to get it using the docker volume mechanism?</p>
  
  <p>Docker version is 18.04.0-ce, build 3d479c0af6.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The relevant code regarding how the program saves the output file <code>result.md</code> is the following:</p>
  
  <pre><code>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 &lt;&lt; some_data &lt;&lt; etc &lt;&lt; std::endl;
  ...
  output_file.close();
  </code></pre>
  
  <p>In practice, the program is run as <code>program file1 file2</code>, and the output will be saved in the working directory, not matter if its the same where <code>program</code> is placed or not.</p>