在Docker容器中自定义RStudio环境 [英] Customizing RStudio environment in Docker container

查看:169
本文介绍了在Docker容器中自定义RStudio环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 10 Pro的Docker容器中使用RStudio。
我使用RStudio rocker / rstudio https://hub.docker.com/u/rocker/

I use RStudio in Docker container in Windows 10 Pro. I use RStudio rocker/rstudio image pulled from https://hub.docker.com/u/rocker/.

要启动容器,我执行了命令:

To start container I executed command:

docker run -d -p 8787:8787 -v //c/Users/<My name>/Documents/R/Rprojects:/home/rstudio/ rocker/rstudio

然后我可以通过以下链接从浏览器访问服务器:
http:// localhost:8787 / 。一切正常。

And then I can access the server from my browser by following link: http://localhost:8787/. Everything works fine.

我要做的是对RStudio环境进行一些自定义。特别是,我将工具 /全局选项 /编辑器主题更改为暗色上的粉彩。我应用了此选项,但是只有在容器还活着的时候它才会持续存在。重新启动容器时,自定义选项全部消失。

What I want to do is some customization of the RStudio environment. In particular, I changed Tools/Global options/Editor theme to 'Pastel on Dark'. I applied this option but it persists only when the container alive. When I restart the container custom options are all gone.

我的项目保存在运行容器时指示的文件夹中,但全局选项未保存。

My projects are saved in the folder that I indicated when running container, but global options are not.

因此,如何将全局选项也保存在硬盘上。也许我需要在驱动器上公开另一个文件夹,该文件夹将连接到RStudio保存全局选项的容器文件夹?

So, how can I save also global options on my hard drive. Maybe I need to expose another folder on my drive which will connect to container folder where RStudio saves global options?

是否可以在 dockerfile 作为docker映像中的新层?

Is it possible to predefine global options in dockerfile as a new layer in docker image?

推荐答案

如果像我一样,您使用临时容器(使用-rm 标志),然后在停止时删除该容器。这是一件好事,因为它可以确保每次都100%保持干净的环境,但是这意味着各个会话之间都不会保留设置。

If, like me, you use an ephemeral container (using the --rm flag), then the container gets deleted when stopped. This is a good thing as it ensures a 100% clean environment every time but it means settings are not preserved from session to session.

与许多流行的IDE不同,rstudio设置不会存储在用户可访问的透明json,尽管他们正在研究

Unlike many popular IDE, rstudio settings are not stored in a user-accessible transparent json, although they are working on it.

一种解决方法是将设置复制到正确的位置:

A workaround is copying over the settings to the right location:


  • 键绑定: / home / rstudio /。 R / rstudio / keybindings / rstudio_bindings.json

  • 常规设置(例如主题): /home/rstudio/.rstudio/monitored / user-settings

  • keybindings: /home/rstudio/.R/rstudio/keybindings/rstudio_bindings.json
  • general settings (such as theme): /home/rstudio/.rstudio/monitored/user-settings

要进行设置:


  1. 在容器中启动rstudio

  2. 设置所需的设置

  3. 在主机上的某个位置备份上面列出的2个文件。

  4. 每次启动rstudio时都复制配置文件-请参见下面的脚本。

  1. Launch rstudio in a container
  2. Set your desired settings
  3. Back up the 2 files listed above somewhere on your host.
  4. Copy over the config files every time you start rstudio - see script below.

我创建了一个快速的lau快捷键指向以下易于修改的脚本。它会启动一个名为rstudio的容器,并复制我备份的设置(在我的情况下是从 / home / asac / projects / rstudio-config

I have created a quick launch shortcut pointing to the following script which is easily adapted. It starts a container named rstudio and copies over the settings I have backed up (in my case from /home/asac/projects/rstudio-config)

#!/bin/bash                                     
                         
echo Running rstudio on localhost:8787                 
docker run -d --rm -p 8787:8787 -e PASSWORD=<pwd> \                       
-v /home/asac/projects:/home/rstudio/projects \                          
-v /home/asac/data:/home/rstudio/data \                                  
--name rstudio asachet/shiny-dev                                         
                                                                         
echo Copying over rstudio settings                                       
docker exec rstudio mkdir /home/rstudio/.R/rstudio/keybindings -p        
docker cp /home/asac/projects/rstudio-config/user-settings rstudio:/home/rstudio/.rstudio/monitored/user-settings
docker cp /home/asac/projects/rstudio-config/rstudio_bindings.json rstudio:/home/rstudio/.R/rstudio/keybindings/rstudio_bindings.json
                                                                         
echo Launching browser                                                   
xdg-open http://localhost:8787      


2020年新增


对于RStudio v1.3,有一个新文件〜/ .config / rstudio / rstudio-prefs.json 的设置。您可以在机器之间复制它或手动编辑它。

NEW IN 2020

With RStudio v1.3, there is a new file ~/.config/rstudio/rstudio-prefs.json which controls all of the settings. You can copy it between machines or hand-edit it.

更多详细信息 ,该版本已移植到1.3版中。

More details in the RStudio Server PR which got ported to RStudio in version 1.3.

这篇关于在Docker容器中自定义RStudio环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆