<?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: Héctor Pascual</title>
    <description>The latest articles on DEV Community by Héctor Pascual (@hectorpascual).</description>
    <link>https://dev.to/hectorpascual</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F172293%2Fd90617b4-27dc-4a37-b802-4044fa82cf4a.jpg</url>
      <title>DEV Community: Héctor Pascual</title>
      <link>https://dev.to/hectorpascual</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hectorpascual"/>
    <language>en</language>
    <item>
      <title>Git merge, merge-squash and rebase simplified</title>
      <dc:creator>Héctor Pascual</dc:creator>
      <pubDate>Fri, 09 Aug 2019 10:17:46 +0000</pubDate>
      <link>https://dev.to/hectorpascual/git-merge-merge-squash-and-rebase-reflexions-418l</link>
      <guid>https://dev.to/hectorpascual/git-merge-merge-squash-and-rebase-reflexions-418l</guid>
      <description>&lt;h1&gt;
  
  
  Git merge, merge-squash and rebase simplified
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Starting the repository with basic files
&lt;/h2&gt;

&lt;p&gt;Lets create an empty repository and commit a file to the master branch:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git init 
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;m1
&lt;span class="nv"&gt;$ &lt;/span&gt;git add m1
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"m1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now we switch to a new branch named feature:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; feature
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Is time to create a file in the feature branch and commit it:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;f1 
&lt;span class="nv"&gt;$ &lt;/span&gt;git add f1 
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"f1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now let's go back to the master and create another file :&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout master
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;m2 
&lt;span class="nv"&gt;$ &lt;/span&gt;git add m2
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"m2"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If we type &lt;code&gt;$ git log&lt;/code&gt; we will see this : &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* 60c3a2b - (1 second ago) m2 - Hector (HEAD -&amp;gt; master)
| * 7832858 - (87 seconds ago) f1 - Hector (feature)
|/  
* 0a950f5 - (5 minutes ago) m1 - Hector
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Integrating changes from master to feature branch
&lt;/h2&gt;

&lt;p&gt;Up to now we have one simple feature branch with a commit and two commits in the master branch, it is a common practice to integrate the commits from the master branch to our feature in order to avoid losing track of master changes, but there are a few ways to do it : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Git merge&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout feature 
&lt;span class="nv"&gt;$ &lt;/span&gt;git merge master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is a non-destructive way, branches keep preserved its history and only a merge commit appears :&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*   fad9250 - (11 seconds ago) Merge branch 'master' into feature - Hector (HEAD -&amp;gt; feature)
|\  
| * 60c3a2b - (5 minutes ago) m2 - Hector (master)
* | 7832858 - (7 minutes ago) f1 - Hector
|/  
* 0a950f5 - (11 minutes ago) m1 - Hector
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Git merge --squash&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout feature 
&lt;span class="nv"&gt;$ &lt;/span&gt;git merge &lt;span class="nt"&gt;--squash&lt;/span&gt; master
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Squash"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is a non-destructive way as well, branches keep preserved its history but now no merge commit appears, all the changes in master are grouped into 1 commit named Squash in my case and appears as as a single commit in the feature branch, as you can see : &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* dc4e5b7 - (10 seconds ago) Squash - Hector (HEAD -&amp;gt; feature)
* 7832858 - (19 minutes ago) f1 - Hector
| * 60c3a2b - (18 minutes ago) m2 - Hector (master)
|/  
* 0a950f5 - (23 minutes ago) m1 - Hector
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Git rebase&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout feature 
&lt;span class="nv"&gt;$ &lt;/span&gt;git rebase master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;With rebase instead, the history will be simpler, what it does in high-level words is to search for the last common commit and add master commits upon it but below our branch commits.&lt;/p&gt;

&lt;p&gt;As you can see m2 commit is &lt;strong&gt;upon&lt;/strong&gt; m1 (last common commit in both branches) and &lt;strong&gt;below&lt;/strong&gt; f1 (our feature branch commit)&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* 6074794 - (11 minutes ago) f1 - Hector (HEAD -&amp;gt; feature)
* 60c3a2b - (10 minutes ago) m2 - Hector (master)
* 0a950f5 - (15 minutes ago) m1 - Hector
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Integrating changes from feature branch to master
&lt;/h2&gt;

&lt;p&gt;Let's suppose we integrate master changes to feature branch with merge and we add some few changes to both branches, m3 and f2 resulting to this log :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* 83c98e1 - (1 second ago) m3 - Hector (HEAD -&amp;gt; master)
| * 0a3663c - (2 minutes ago) f2 - Hector (feature)
| *   edfda02 - (2 minutes ago) Merge branch 'master' into feature - Hector
| |\  
| |/  
|/|   
* | 60c3a2b - (29 minutes ago) m2 - Hector
| * 490a167 - (3 minutes ago) f1 - Hector
|/  
* 0a950f5 - (35 minutes ago) m1 - Hector
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As before, we have the same 3 options :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Git merge&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we do a &lt;code&gt;$ git merge feature&lt;/code&gt; it will result as it follows :&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*   d6b643b - (4 seconds ago) Merge branch 'feature' - Hector (HEAD -&amp;gt; master)
|\  
| * 0a3663c - (4 minutes ago) f2 - Hector (feature)
| *   edfda02 - (4 minutes ago) Merge branch 'master' into feature - Hector
| |\  
| * | 490a167 - (4 minutes ago) f1 - Hector
* | | 83c98e1 - (2 minutes ago) m3 - Hector
| |/  
|/|   
* | 60c3a2b - (31 minutes ago) m2 - Hector
|/  
* 0a950f5 - (36 minutes ago) m1 - Hector
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Git merge --squash&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we do a squash :&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git merge &lt;span class="nt"&gt;--squash&lt;/span&gt; feature
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Squash"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;With the behaviour expected, not a merge commit and non-destructive history we get :&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* 63f7387 - (10 seconds ago) Squash - Hector (HEAD -&amp;gt; master)
* 83c98e1 - (3 minutes ago) m3 - Hector
| * 0a3663c - (5 minutes ago) f2 - Hector (feature)
| *   edfda02 - (5 minutes ago) Merge branch 'master' into feature - Hector
| |\  
| |/  
|/|   
* | 60c3a2b - (32 minutes ago) m2 - Hector
| * 490a167 - (5 minutes ago) f1 - Hector
|/  
* 0a950f5 - (37 minutes ago) m1 - Hector
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Git rebase&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, let's test what would happen with &lt;code&gt;$ git rebase feature&lt;/code&gt; we obtain the following log :&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* 6c6ba0e - (5 minutes ago) m3 - Hector (HEAD -&amp;gt; master)
* 0a3663c - (7 minutes ago) f2 - Hector (feature)
*   edfda02 - (7 minutes ago) Merge branch 'master' into feature - Hector
|\  
| * 60c3a2b - (35 minutes ago) m2 - Hector
* | 490a167 - (8 minutes ago) f1 - Hector
|/  
* 0a950f5 - (40 minutes ago) m1 - Hector
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Rebase takes the last common commit, which is the merge commit and add places the f2 commit upon it, but below the m3 commit from master.&lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>Docker in Docker, managing existant volumes</title>
      <dc:creator>Héctor Pascual</dc:creator>
      <pubDate>Thu, 11 Jul 2019 08:11:25 +0000</pubDate>
      <link>https://dev.to/hectorpascual/docker-in-docker-managing-existant-volumes-ck5</link>
      <guid>https://dev.to/hectorpascual/docker-in-docker-managing-existant-volumes-ck5</guid>
      <description>&lt;p&gt;Introducing the context, I am working with a docker container that runs jenkins, inside it there are some other docker services running aswell, brought up during some jenkins job execution.&lt;/p&gt;

&lt;p&gt;As an existant volume I refer to a folder containing data that I will mount to the container, for instance :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker run ... -v  /folder/with/data:/var/data ...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The command I use to run jenkins is the following one :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="se"&gt;\ &lt;/span&gt;                                       
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="se"&gt;\ &lt;/span&gt;              
  &lt;span class="nt"&gt;-u&lt;/span&gt;  &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-p&lt;/span&gt; 8080:8080 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-v&lt;/span&gt; /data/jenkins_test:/var/jenkins_home &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-v&lt;/span&gt; /var/run/docker.sock:/var/run/docker.sock &lt;span class="se"&gt;\&lt;/span&gt;
  shimmi/jenkins
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see the &lt;em&gt;docker socket&lt;/em&gt;, which is the main entry point for docker API is mapped as a volume into the container, that means, that the docker engine will be "&lt;strong&gt;shared&lt;/strong&gt;" (it will be the same docker socket) and volumes, images and containers will be shared inside and outside the container.&lt;/p&gt;

&lt;p&gt;This is a relevant point that caused me a lot of headache trying to figure why once I run a container &lt;strong&gt;inside jenkins&lt;/strong&gt;, the path specified as existant volumes when creating containers were not found or empty. &lt;/p&gt;

&lt;p&gt;The problem was that the path I was specifying was the correct for the jenkins container but Docker was trying to search for it in the host that runs the jenkins container (my machine filesystem) not in the jenkins container itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  About volumes and docker-compose
&lt;/h2&gt;

&lt;p&gt;Specifically the services I bring up are specified in a docker-compose file, in order to use existant volumes from the host you have to declare a top level &lt;strong&gt;volumes&lt;/strong&gt; option and set the external property as true :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="s"&gt;&amp;lt;myVolume&amp;gt;&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;external&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And now, if this is an existant volume in your docker host you should be able to use it. &lt;/p&gt;

&lt;h2&gt;
  
  
  Creating volumes from existing data folders
&lt;/h2&gt;

&lt;p&gt;In my case I wanted to create a volume and "link" it to some folder with data, not an empty volume, in order to do that I followed these steps :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker volume create &amp;lt;myVolume&amp;gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;docker volume inspect &amp;lt;myVolume&amp;gt; 
&lt;span class="o"&gt;[&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"CreatedAt"&lt;/span&gt;: &lt;span class="s2"&gt;"0001-01-01T00:00:00Z"&lt;/span&gt;,
        &lt;span class="s2"&gt;"Driver"&lt;/span&gt;: &lt;span class="s2"&gt;"local"&lt;/span&gt;,
        &lt;span class="s2"&gt;"Labels"&lt;/span&gt;: &lt;span class="o"&gt;{}&lt;/span&gt;,
        &lt;span class="s2"&gt;"Mountpoint"&lt;/span&gt;: &lt;span class="s2"&gt;"/var/lib/docker/volumes/&amp;lt;myVolume&amp;gt;/_data"&lt;/span&gt;,
        &lt;span class="s2"&gt;"Name"&lt;/span&gt;: &lt;span class="s2"&gt;"&amp;lt;myVolume&amp;gt;"&lt;/span&gt;,
        &lt;span class="s2"&gt;"Options"&lt;/span&gt;: &lt;span class="o"&gt;{}&lt;/span&gt;,
        &lt;span class="s2"&gt;"Scope"&lt;/span&gt;: &lt;span class="s2"&gt;"local"&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="c"&gt;# See the mountpoint is the path we will link&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /var/lib/docker/volumes/&amp;lt;myVolume&amp;gt;/_data
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &amp;lt;MY_FOLDER_WITH_DATA&amp;gt; /var/lib/docker/volumes/&amp;lt;myVolume&amp;gt;/_data
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That way, you can bring up containers inside another containers (docker in docker) managing volumes with data in an easy way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bash script
&lt;/h3&gt;

&lt;p&gt;In order to automate the task of creating a volume and the symlink I wrote a bash script :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;# This script creates a docker volume and links it to a existing folder that contains data.&lt;/span&gt;

&lt;span class="c"&gt;# Arg1 : volume name&lt;/span&gt;
&lt;span class="c"&gt;# Arg2 : existant folder with data to create the volume&lt;/span&gt;

&lt;span class="nv"&gt;ARG1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;
&lt;span class="nv"&gt;ARG2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;

&lt;span class="k"&gt;function &lt;/span&gt;create_volume &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'$1 = '&lt;/span&gt; &lt;span class="nv"&gt;$ARG1&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'$2 = '&lt;/span&gt; &lt;span class="nv"&gt;$ARG2&lt;/span&gt;
    docker volume create &lt;span class="nv"&gt;$ARG1&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; &lt;span class="nt"&gt;-ne&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;
      &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Script failed"&lt;/span&gt;
        &lt;span class="nb"&gt;exit &lt;/span&gt;1
    &lt;span class="k"&gt;fi
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Volume created!"&lt;/span&gt;
    &lt;span class="nb"&gt;sudo rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /var/lib/docker/volumes/&lt;span class="nv"&gt;$ARG1&lt;/span&gt;/_data
    &lt;span class="nb"&gt;sudo ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nv"&gt;$ARG2&lt;/span&gt; /var/lib/docker/volumes/&lt;span class="nv"&gt;$ARG1&lt;/span&gt;/_data
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; &lt;span class="nt"&gt;-ne&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;
      &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Script failed"&lt;/span&gt;
        &lt;span class="nb"&gt;exit &lt;/span&gt;1
    &lt;span class="k"&gt;fi
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Folder linked"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Script executed succesfully"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$# &lt;/span&gt;&lt;span class="nt"&gt;-eq&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"No arguments supplied, specify the volume name and the path of the folder"&lt;/span&gt;
    &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi

if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$# &lt;/span&gt;&lt;span class="nt"&gt;-eq&lt;/span&gt; 1 &lt;span class="o"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Not enough arguments supplied, specify the volume name and the path of the folder"&lt;/span&gt;
    &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi

&lt;/span&gt;&lt;span class="nv"&gt;EXISTS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;docker volume &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$ARG1&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-w&lt;/span&gt; ARG1&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$EXISTS&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then 
    &lt;/span&gt;&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"A volume with this name already exists. &lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;$'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s1"&gt;&amp;gt; '&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="s2"&gt;Do you want to delete it and create it again linked to the specified path (y/n) ?"&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 1 &lt;span class="nt"&gt;-r&lt;/span&gt;
    &lt;span class="nb"&gt;echo
    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$REPLY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^[Yy]&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;
    &lt;span class="k"&gt;then
        if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"/var/lib/docker/volumes/&lt;/span&gt;&lt;span class="nv"&gt;$ARG1&lt;/span&gt;&lt;span class="s2"&gt;/_data"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
            &lt;/span&gt;&lt;span class="nb"&gt;unlink&lt;/span&gt; /var/lib/docker/volumes/&lt;span class="nv"&gt;$ARG1&lt;/span&gt;/_data
            &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"_data folder unlinked!"&lt;/span&gt;
        &lt;span class="k"&gt;fi
        &lt;/span&gt;docker volume &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nv"&gt;$ARG1&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; &lt;span class="nt"&gt;-ne&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;
          &lt;span class="k"&gt;then
            &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Please stop the containers using this volume before launching the script"&lt;/span&gt;
            &lt;span class="nb"&gt;exit &lt;/span&gt;1
        &lt;span class="k"&gt;fi
        &lt;/span&gt;create_volume
    &lt;span class="k"&gt;fi
else 
    &lt;/span&gt;create_volume
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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