<p>Trying to copy files from the container to the local first</p>
<p>So, I have a custom Dockerfile, RUN mkdir /test1 &amp;&amp; touch /test1/1.txt and then I build my image and I have created an empty folder in local path /root/test1</p>
<p>and docker run -d --name container1 -v /root/test1:/test1 Image:1</p>
<p>I tried to copy files from containers to the local folder, and I wanted to use it later on. but it is taking my local folder as a preceding and making my container empty.</p>
<p>Could you please someone help me here?</p>
<p>For example, I have built my own custom Jenkins file, for the first time while launching it I need to copy all the configurations and changes locally from the container, and later if wanted to delete my container and launch it again don't need to configure from the scratch.</p>
<p>Thanks,</p>

Siva
<p>The relatively new <code>--mount</code> flag replaces the <code>-v/--volume</code> mount. It's easier to understand (syntactically) and is also more verbose (see <a href="https://docs.docker.com/storage/volumes/" rel="nofollow noreferrer">https://docs.docker.com/storage/volumes/</a>).</p>
<p>You can mount and copy with:</p>
<pre><code>docker run -i \
           --rm \
           --mount type=bind,source=&quot;$(pwd)&quot;/root/test1,target=/test1 \
            /bin/bash &lt;&lt; COMMANDS
                cp &lt;files&gt; /test1
            COMMANDS
</code></pre>
<p>where you need to adjust the <code>cp</code> command to your needs. I'm not sure if you need the <code>&quot;$(pwd)&quot;</code> part.</p>
