<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jeet Parekh</title>
    <description>The latest articles on DEV Community by Jeet Parekh (@jeetparekh).</description>
    <link>https://dev.to/jeetparekh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F541341%2Fefc8e9bf-e321-47e9-a0cf-a26652a24fa5.jpg</url>
      <title>DEV Community: Jeet Parekh</title>
      <link>https://dev.to/jeetparekh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jeetparekh"/>
    <language>en</language>
    <item>
      <title>Transferring data across docker or podman volumes</title>
      <dc:creator>Jeet Parekh</dc:creator>
      <pubDate>Wed, 26 May 2021 14:05:30 +0000</pubDate>
      <link>https://dev.to/jeetparekh/transferring-data-across-docker-podman-volumes-3c9a</link>
      <guid>https://dev.to/jeetparekh/transferring-data-across-docker-podman-volumes-3c9a</guid>
      <description>&lt;p&gt;I often find myself starting temporary containers to transfer data between the local file-system and container volumes. Or sometimes, between volumes. And the entire process is a bit tedious. Starting a temporary container, mounting the volume, mounting the local file-system, and finally transferring the data.&lt;/p&gt;

&lt;p&gt;So I made a python script which makes this easy. I call it &lt;code&gt;cvcp&lt;/code&gt; - container volume cp (copy). It actually does not use &lt;code&gt;cp&lt;/code&gt; though. It uses &lt;code&gt;rsync&lt;/code&gt; for the data transfer. So it's necessary to have a container image with &lt;code&gt;rsync&lt;/code&gt; installed.&lt;/p&gt;

&lt;p&gt;You can find the script at &lt;a href="https://github.com/jeet-parekh/cvcp"&gt;https://github.com/jeet-parekh/cvcp&lt;/a&gt;. The repository also contains a &lt;code&gt;Dockerfile&lt;/code&gt; which will build an image with &lt;code&gt;rsync&lt;/code&gt; installed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Using cvcp
&lt;/h2&gt;

&lt;p&gt;Download the file &lt;code&gt;cvcp&lt;/code&gt; from the repository and place it inside your preferred path. I prefer &lt;code&gt;~/bin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then, to use &lt;code&gt;cvcp&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cvcp SOURCE DESTINATION
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Path inside a container volume should be written as &lt;code&gt;&amp;lt;volume_name&amp;gt;:&amp;lt;path_inside_volume&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Either &lt;code&gt;SOURCE&lt;/code&gt; or &lt;code&gt;DESTINATION&lt;/code&gt; can be a local path or a path inside a container volume. Note however that both &lt;code&gt;SOURCE&lt;/code&gt; and &lt;code&gt;DESTINATION&lt;/code&gt; cannot be local paths.&lt;/p&gt;

&lt;p&gt;If you use &lt;code&gt;cvcp&lt;/code&gt; without any options, it will pull a &lt;code&gt;rsync&lt;/code&gt; image from Docker Hub, and will use docker with root (&lt;code&gt;sudo docker&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;The following command line options are available to customise the behaviour:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--docker&lt;/code&gt; and &lt;code&gt;--podman&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The container engine to use.&lt;/li&gt;
&lt;li&gt;The default is &lt;code&gt;docker&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;code&gt;--rootless&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the container engine without root (without &lt;code&gt;sudo&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;code&gt;--image&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The container image to be used.&lt;/li&gt;
&lt;li&gt;Note that the image needs to have &lt;code&gt;rsync&lt;/code&gt; installed. Read the next section for more details.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;code&gt;--rsync-opts&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Options to pass to &lt;code&gt;rsync&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Note that, you need to pass all the options as a quoted string &lt;strong&gt;with a space at the beginning&lt;/strong&gt;. For example, &lt;code&gt;' --verbose'&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Using this option will clear the default &lt;code&gt;rsync&lt;/code&gt; options used by &lt;code&gt;cvcp&lt;/code&gt;, so make sure to pass all the options required.&lt;/li&gt;
&lt;li&gt;The default options are &lt;code&gt;' -a --progress'&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;code&gt;--no-exec&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Print the command and exit.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Using a custom image
&lt;/h2&gt;

&lt;p&gt;To use a custom image with &lt;code&gt;cvcp&lt;/code&gt;, use the &lt;code&gt;--image&lt;/code&gt; argument.&lt;/p&gt;

&lt;p&gt;To permanently change the default image that &lt;code&gt;cvcp&lt;/code&gt; uses, change this line in the &lt;code&gt;cvcp&lt;/code&gt; script file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;RSYNC_IMAGE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"image_name"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is necessary for your custom image to have &lt;code&gt;rsync&lt;/code&gt; installed. You can use the Dockerfile inside the same repository as a base to build the image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# docker&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; localhost/rsync &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# podman&lt;/span&gt;
podman build &lt;span class="nt"&gt;-t&lt;/span&gt; localhost/rsync &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>docker</category>
      <category>python</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
