前言
需要将项目部署到Docker中,我之前也没有接触过这个,纯萌新记录一下整个过程。
注意:整个流程对于我来说是能成功跑通的,但我也不知道有没有冗余操作(因为我也不太懂),欢迎大家提出宝贵意见~
我的配置环境
主系统:Windows 10
子系统:
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
有可以翻墙的梯子,所以下载与上传过程我都没使用镜像链接,如果大家在网速上有问题的话可以去搜一下怎么配置镜像。
过程
1. 安装Windows版Docker
(安装时候没有记录过程,这步是凭着记忆写的,如果遇到问题只能善用搜索了)
在Docker的官网下载windows桌面版,点击页面中蓝色的Docker Desktop for Windows
下载,解压到本地。
之后是注册账户,选择免费的个人版本即可。
安装过程我记得还是遇到了一点小问题,后面根据官方给的中文解决方案和网上的安装教程装好了,主要是将WSL升级为WSL2。
有了这两个图标就算是安装好软件了(大的是快捷方式,小的在状态栏)
在ubuntu子系统中输入docker run hello-world
,出现下面内容就说明配置完成。
$ sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
2. 本地部署所需环境
1. 新建shiny用户
这步非常重要,一定要执行。(血泪经验)
进入root权限,添加shiny用户,这样可以避免很多问题,因为shiny-server的默认使用用户是shiny。
su
useradd shiny
passwd shiny
这里的过程我没截图,我也是按照知乎上的一个教程上来的,就借用他的图片了,该文在参考部分有引用。
在用户列表添加shiny账户的root权限,将/sudoers文件权限改为可编辑并添加。
(这里需要读者具有一定的vim知识,方便大家操作,我将给出一些基础的操作,详细的请自己去学习。
打开文件默认是在阅读模式
,光标操作就用键盘的↑↓←→
,找到位置后按a
在光标后进入编辑模式
,按i
在光标前进入编辑模式。按esc
退出编辑模式进入阅读模式,这时按住shift
+z
+z
是保存并退出
,按住shift
+z
+q
是不保存直接退出
)
chmod +w /etc/sudoers
vim /etc/sudoers
切换到shiny用户环境。
su - shiny #输入后若出现No directory提示,忽略即可。
安装shiny包,即使在主环境安装过shiny也要装!每个用户都有自己的环境配置。
sudo R -e "install.packages('shiny')"
如果出现permission denied
错误提示你权限不够,在命令最开始加上sudo
。
至此准备工作已完成,下面是shiny-server的安装部署。
2. 配置shiny-server环境
进入到srv目录下,下载最新的shiny-server的deb,最新版本见官网。
cd /srv
sudo apt-get install gdebi-core
sudo wget https://download3.rstudio.org/ubuntu