title: Mount volume with docker-compose for Jupyter and RStudio instance
body: <p>I am learning Docker and managed to create a <em>RStudio instance</em> and a <em>Jupyter Notebook</em> instance using <em>docker-compose</em> building an image.
  While I can log in and create scripts from the instances, I noticed these scripts are not saved "persistently", and I cannot find them in my main folders <code>/home/rstudio_scripts</code> and <code>home/jupyter_scripts</code>.</p>
  
  <p>I have learned that in order for the scripts/data created in these instances to be "persistent" even after docker containers are down, you need to mount volumes.</p>
  
  <p>So I have tried to mount volumes and create a specific folder for RStudio &amp; Jupyter in the docker-compose.yml below:</p>
  
  <p><a href="https://i.stack.imgur.com/Pjjuw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pjjuw.png" alt="enter image description here"></a></p>
  
  <p>But there is clearly something wrong as neither the folders nor the data appear.</p>
  
  <p>My <em>docker-compose.yml</em> and the <em>Dockerfile</em> for RStudio are both in a folder called <em>Docker</em>, that is within this folder that I am building the image docker <code>build -t general_docker .</code></p>
  
  <p>I would also like that any data created either in the Rstudio or Jupyter instance can be read/write by both instances, but I don't know if I should use something like <code>chmod 777 ...</code> after, when the containers are running.</p>
  
  <p>Any help much appreciated !</p>
  
  <p><strong>EDIT 1</strong>: Let me attach the updated docker-compose.yml. The following allow me to have a new folder I created in the home directory called <em>R_and_Jupyter_scripts</em> containing all my scripts, to be accessible in my Rstudio instance as well as my Jupyter notebook. But I would like that any new script created from the Jupyter or RStudio instance does not disappear after doing 'docker-compose down'. What part of the <em>docker-compose.yml</em> should I change?</p>
  
  <pre><code>version: "3.5"
  services:
    rstudio:
      environment:
        - USER=username
        - PASSWORD=password
      image: "rocker/tidyverse:latest"
      build:
       context: ./
       dockerfile: Dockerfile
      volumes:
        - $HOME/R_and_Jupyter_scripts:/home/rstudio/r_scripts
      container_name: rstudio
      ports:
       - 8787:8787
  
    jupyter:
      image: 'jupyter/datascience-notebook:latest'
      ports:
       - 8888:8888
      volumes:
        - $HOME/R_and_Jupyter_scripts:/home/jovyan/work
      container_name: jupyter
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I have edited the code above to write in volumes only absolute paths (see below) but still does not do what I need.</p>
  
  <p>I have created a text file <code>output.txt</code> from RStudio and when I do <code>sudo find / -name "output.txt"</code> I expect this file to be in <code>/home/ec2-user/R_and_Jupyter_scripts</code>
  but it ends up being in two different places that look like folders that are still in the container itself:</p>
  
  <pre><code>/var/lib/docker/overlay2/66513c53c04786298cac012ea032be58d434131ce04e73f75bf63ca1d0e358d6/diff/home/maxence/r_scripts/output.txt
  </code></pre>
  
  <p>and</p>
  
  <pre><code>/var/lib/docker/overlay2/66513c53c04786298cac012ea032be58d434131ce04e73f75bf63ca1d0e358d6/merged/home/maxence/r_scripts/output.txt
  </code></pre>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>version: "3.5"
  services:
    rstudio:
      environment:
        - USER=username
        - PASSWORD=password
      image: "rocker/tidyverse:latest"
      build:
       context: ./
       dockerfile: Dockerfile
      volumes:
        - /home/ec2-user/R_and_Jupyter_scripts:/home/rstudio/r_scripts
      container_name: rstudio
      ports:
       - 8787:8787
  
    jupyter:
      image: 'jupyter/datascience-notebook:latest'
      ports:
       - 8888:8888
      volumes:
        - /home/ec2-user/R_and_Jupyter_scripts:/home/jovyan/work
      container_name: jupyter
  </code></pre>