<p>I would suggest the following <a href="https://stackoverflow.com/a/38228877/19238131">approach</a> for the files within your <code>docker-compose.yml</code>:</p>
<pre><code>volumes:
    - ./config:/path/to
    - ./input:/directory/with/input_files
    - ./output:/directory/with/output_files
</code></pre>
<p><em>Do note</em> that I mount the entire folder in this example, despite you only mentioning one config file. This is on purpose - reasons for that are well explained within <a href="https://www.youtube.com/watch?v=oXfL0UCO9F4" rel="nofollow noreferrer">this video</a>. Resources on how to define <code>docker-compose.yml</code> in full can be found <a href="https://docs.docker.com/compose/gettingstarted/" rel="nofollow noreferrer">here</a>. Your final approach could look something like this:</p>
<ol>
<li>Push Dockerfile to registry of your choice</li>
<li>Provide user the <code>docker-compose.yml</code> for example via Git</li>
<li>User creates folder with the necessary sub-directories (<code>config</code>, <code>input</code> and <code>output</code> in this example)</li>
<li>User supplies valid config file in <code>config</code> folder</li>
<li>User executes <code>docker-compose up -d</code></li>
<li>Success :)</li>
</ol>

CC BY-SA 4.0
2023-06-07T12:28:27.177Z
2023-06-07T12:28:27.177Z
YoshiMbele
<p>I am working to containerize a program. The program requires a configuration file and directories for its operation, which are passed as command line arguments, e.g. something like this:</p>
<pre class="lang-sh prettyprint-override"><code>$ myprog -c /path/to/config.conf -i /directory/with/input_files -o /directory/with/output_files
</code></pre>
<p>I know that I will need mount docker volumes to the containerized version of this program  so that it can access the config file and directories. But, I would like to maintain the command-line interface unchanged (as far as possible) to hide the complexity of using docker volumes, etc. from users. How do I do this?</p>
<p>Will I need to create a wrapper script that maps the values of the command-line arguments (<code>-c</code>, <code>-i</code>, <code>-o</code>) to mount the corresponding paths as docker volumes? If so, what is the best practice for packaging it (i.e. to distribute the script with the container) and making this work cross-platform (i.e. so that it runs on Windows, MacOS, Linux)?</p>

<docker><containers>
What is best practice for passing files and directories as command line arguments to a containerized program?
packoman
# What is best practice for passing files and directories as command line arguments to a containerized program?

(Asked by: username_0 on 2023-06-07)

I am working to containerize a program. The program requires a configuration file and directories for its operation, which are passed as command line arguments, e.g. something like this:
$ myprog -c /path/to/config.conf -i /directory/with/input_files -o /directory/with/output_files

I know that I will need mount docker volumes to the containerized version of this program  so that it can access the config file and directories. But, I would like to maintain the command-line interface unchanged (as far as possible) to hide the complexity of using docker volumes, etc. from users. How do I do this?
Will I need to create a wrapper script that maps the values of the command-line arguments (-c, -i, -o) to mount the corresponding paths as docker volumes? If so, what is the best practice for packaging it (i.e. to distribute the script with the container) and making this work cross-platform (i.e. so that it runs on Windows, MacOS, Linux)?

**Tags:** docker, containers


---

## 1 answers

### Answer by username_1 on 2023-06-07. Score: 0

I would suggest the following approach for the files within your docker-compose.yml:
volumes:
    - ./config:/path/to
    - ./input:/directory/with/input_files
    - ./output:/directory/with/output_files

Do note that I mount the entire folder in this example, despite you only mentioning one config file. This is on purpose - reasons for that are well explained within this video. Resources on how to define docker-compose.yml in full can be found here. Your final approach could look something like this:

Push Dockerfile to registry of your choice
Provide user the docker-compose.yml for example via Git
User creates folder with the necessary sub-directories (config, input and output in this example)
User supplies valid config file in config folder
User executes docker-compose up -d
Success :)


---

