我正在尝试使用docker-compose创建映像来创建RStudio实例和Jupyter Notebook实例。我可以创建这些实例,但是装入的卷似乎不是“永久的”。
下面是我的文件夹的树形结构:
.
├── Docker
│ ├── docker-compose.yml
│ └── Dockerfile
└── R_and_Jupyter_scripts
└── files_already_there.txt
我想要:
1] files_already_there.txt
可在我的RStudio和Jupyter Notebook实例中使用。
2)从两个实例之一创建的任何新文件/脚本都将显示在具有读取/写入权限的R_and_Jupyter_scripts
文件夹中。 i.e:我从RStudio实例创建了一个文本文件“ output.txt”,但是当我检查路径时,文件的保存位置在这里:
sudo find / -name "output.txt"
/var/lib/docker/overlay2/821d3d087948309e3c489af29a5263e53e5f72627e903b4285a9597214412840/diff/home/maxence/output.txt
/var/lib/docker/overlay2/821d3d087948309e3c489af29a5263e53e5f72627e903b4285a9597214412840/merged/home/maxence/output.txt
下面是我当前的docker-compose.yml,您能确定出什么问题了吗?
version: "3.5"
services:
rstudio:
environment:
- USER=maxence
- PASSWORD=password
image: "rocker/tidyverse:latest"
build:
context: ./
dockerfile: Dockerfile
volumes:
- /home/ec2-user/R_and_Jupyter_scripts:/var/lib/docker/
container_name: rstudio
ports:
- 8787:8787
jupyter:
image: 'jupyter/datascience-notebook:latest'
ports:
- 8888:8888
volumes:
- /home/ec2-user/R_and_Jupyter_scripts:/var/lib/docker/
container_name: jupyter
非常感谢。
我没有您的Dockerfile,看起来您正在运行一个Amazon实例,因此我无法确定是否复制此文件,但是如果我删除Dockerfile部分并进行其他一些编辑,则可以对自己的作品进行修改Ubuntu 18机器。
version: "3.5"
services:
rstudio:
environment:
- USER=maxence
- PASSWORD=password
image: "rocker/tidyverse:latest"
volumes:
- /tmp/R_and_Jupyter_scripts:/home/maxence/R_and_Jupyter_scripts
container_name: rstudio
ports:
- 8787:8787
jupyter:
image: 'jupyter/datascience-notebook:latest'
ports:
- 8888:8888
volumes:
- /tmp/R_and_Jupyter_scripts:/home/joyvan/R_and_Jupyter_scripts
working_dir: /home/joyvan/R_and_Jupyter_scripts
container_name: jupyter
我使用/tmp/R_and_Jupyter_scripts
作为容器外部的位置。
在Rstudio中,创建了/home/maxence
,因为它对应于指定的USER
,这将是您登录时显示的位置。然后我在volume
指令中在此目录下面创建了一个目录,是文件在容器外部的位置。登录Rstudio时,您会看到一个名为R_and_Jupyter_scripts
的文件夹,您可以输入该文件夹并创建所需的内容(我以为working_dir
可以工作,但始终似乎总是在主文件夹中启动)
在您使用的Jupyter图像中,默认用户为joyvan
,因此将自动创建文件夹/home/joyvan
。然后,在volume
和working_dir
指令中使用它。登录时,Jupyter容器将使用此working_dir
。
我测试了它,并在所有3个地方读写了作品。
使用/var/lib/docker
将在每个容器中正确创建一个卷,问题是任何一个客户端都无法将其位置设置为它。