Coder Social home page Coder Social logo

leoatchina / leoatchina-datasci Goto Github PK

View Code? Open in Web Editor NEW
54.0 7.0 26.0 368 KB

基于rstudio、code-server、jupyter-lab的dockerfile,用于快速搭建数据分析环境。

License: MIT License

Python 1.43% Shell 44.04% Dockerfile 23.15% R 31.37%

leoatchina-datasci's Introduction

用集成miniconda3的docker快速布置数据分析平台

前言

众所周知,condadocker是进行快速软件安装、平台布置的两大神器,通过这个软件,在终端前敲几个命令即能安装软件就,出了问题也不会影响到系统配置,能够很轻松的还原和重建。

不过,虽说类似rstudio或者jupyter lab这样的分析平台,已经有别人已经做好的镜像,但是通常是最小化安装,常有系统软件动态库缺失,直接后果是导致部分R包不能安装,而且有时要让不同的镜像协同工作时,目录的映射,权限的设置会让没有经验的人犯晕。比如jupyterlab通常是以root权限运行,生成的文件用rstudio打开就不能保存。

为了克服上述问题,本人设计了一个docker image,集成了rstudio serverjupyter labssh servercode server,可用于数据分析或生信分析平台的快速布置,也可供linux初学者练习用。

安装方法

  • 直接pull(建议使用这种方法)
docker pull leoatchina/datasci
  • build docker镜像 要先装好docker-cegit

主要集成软件

  • 基于ubuntu16.04
  • 安装了大量编译、编辑、下载、搜索等用到的工具和库
  • 安装了最新版miniconda3,Rstudio-server
  • 安装了ssh-server,code-server
  • supervisor启动后台web服务
  • 美化bash界面
  • install_scripts下面的脚本为我收集的一些R包和conda生信软件的安装脚本

2019年8月8日,增加了好多个特性

  • 运行时可以自定义用户名, 用 WKUSER变量指定,默认是datasci。 可指定不小于1000的UID,默认为1000
  • jupyterlabrstudiocode-server都是以上述用户权限运行,这样就解决了原来文件权限不一致的问题,默认密码是datasci, 可用PASSWD变量指定。
  • ssh-server可用root或者自定义用户登陆 ,root密码默认和自定义用户密码一致,可用ROOTPASSWD变量另外指定。
  • 由于jupyterlab非root权限,因此,如不开放ssh端口不以root连入,不能装插件,也不能用apt等装系统软件,只能往自己的用户目录下用conda命令装软件 ,一定程度上提高了安全性。
  • 我是如何解决权限问题的请打开entrypoint.sh这个启动脚本学习。
  • jupyterlab 里集成了table of content, variableinspect, drawio等插件, 使用体验已接近rstudio
  • 内置neovimnodeyarnuctagsgtagsripgrep等软件,能在ssh bash环境下进行用vim进行代码编写。
    • 此处推荐下本人的leoatchina的vim配置使用,接近一个轻型IDE,有按键提示,高亮、补全、运行、检查一应具全。
  • 内置tmux。 这里又推下本人的配置 tmux config
    • ln -s leoatchina-tmux/.tmux.conf ~/.tmux.conf
    • Alt+I插入新tab, Alt+P往前翻,Alt+N往后翻
    • Alt+Shift+I关闭当前tab, Alt+Shift+P往前移,Alt+Shift+N往后移
    • 先导键是M-b
    • 还有其他一些快捷键见源代码学习

2019年10月31号

在实际工作中发现因为jupyterlab服务,是由root账户用以supervisor程序以非root权限启动后,会出现一系列问题,所以现在改用手动启动,相应配置文件直接写入到/opt/config/jupyter_lab_config.py中手动启动,启动后密码同rstudio server

启动方法

用ssh进入后,命令行jupyter lab --config=/opt/config/jupyter_lab_config,然后访问8888端口

内置tmux

我更喜欢启动tmux后再启动jupyter lab, 这样能保证在关掉ssh终端后jupyterlab仍然在运行 。

2020年10月12日

  • 通过改进supervisor的启动代码,code-server也可以普通用户身份自启动
  • code-server 3.5.0要解决ssh证书问题,比较麻烦,还是用3.4.1版本

主要控制点

  • 开放端口:
    • 8888: for jupyter lab
    • 8787: for rstudio server
    • 8686: for code-server
    • 8585: for ssh-server
  • 访问密码:
    • 见dockerfile里的ENV PASSWD=datasci
    • 运行时可以修改密码
  • 目录:
    • 默认/home/datasci或者/home/你指定的用户名,以下以用户名为datasci为例
    • /root目录

一个示范

很多人反应看不明白,那好吧直接给你一个配置文件,首先要安装好docker和docker-compose

git clone http://gitee.com/leoatchina/leoatchina-datasci.git
cd leoatchina-dataci
docker-compose -f bioinfo.yml down && docker-compose -f bioinfo.yml up -d

WINDOWS下把上面的&& 换成 ;, 然后打开http://127.0.0.1:8787, http://127.0.0.1:8686, 用户名和密码都是bioinfo

使用docker-compose命令

  • docker-compose -f datasci.yml up -d
  • docker-compose.yml的详细内容如下
version: "3"  # xml版本
services:
  datasci:
    image: leoatchina/datasci:latest
    environment:
      - PASSWD=yourpasswd  # PASSWD
      - ROOTPASSWD=rootpasswd # 区分普通用户的root密码,如没有,和普通用户相同
      - WKUSER=datasci   # 指定用户名
      - WKUID=23333   # 指定用户ID, 默认是1000
      - WKGID=23333   # 指定用户GROUPID,默认是1000
    ports:     # 端口映射,右边是container里的端口,左边是实际端口
      - 8787:8787
      - 8888:8888
      - 8686:8686
      - 8585:8585
    volumes:   # 位置映射,右docker内部,左实际
      - ./pkgs:/opt/miniconda3/pkgs   # 这个不映射在某些低级内核linux上用conda安装软件时会有问题
      - ./datasci:/home/datasci  # 工作目录, 要和上面的WKUSER一致
      - ./log:/opt/log  # 除rstudio外的log目录
      - ./root:/root # root目录
    container_name: datasci

如上,会生成一个名为datasci的container。 如在启动时想安装其他软件,可以在运行时用build指定一个放有Dockerfile的目录 以上面的yml文件为基础,把image这一行换成build: ./build, 在./build目录下建立Dockerfile ,运行时就会安装tensorflow, opencv

FROM leaotchina/datasci:latest
RUN pip install -q tensorflow_hub
RUN conda install tensorflow && conda install -c menpo opencv

使用docker run命令启动镜像

不推荐这种方法,请自行研究如何

运行后的操作

  • 默认密码各个服务都一样为datasci,可在yml文件里调整
  • ssh-server端口8585,用户名是rootdatasci, 注意root密码可以和普通用户不一致
  • jupyterlab, 通过file->new->terminal输入bash,就会打开一个有高亮的 shell环境 jupyterlab
  • rstudio rstudio
  • code-sever, 要忽略掉warning才能打开 code-server
  • 以此,就可快速布置软件环境并有以下好处
  1. 启动分析流程后,发现代码写错了要强行结束时,只要删除container,不需要一个个去kill进程
  2. 在另一个机器上快速搭建分析环境,把已经装上的软件复制过去就能搭建好分析环境。
  3. 可以用ssh登陆container直接进行代码编写

插件特殊说明

  • rstudiocode-server的插件都会放到/home/datasci
  • jupyterlab labextension install 安装jupyterlab的插件, 最后要build

环境变量


20201116, 回头来看当初还是认识较浅,应该通过yml文件来安装自己的软件包并控制版本,在bioinfo.yml文件里里我放入了可能要用到的生信软件,conda env create --file bioinfo.yml就能安装

众所周知,bash在启动时,会加载用户目录下的.bashrc进行一些系统变量的设置,同时又可以通过source命令加载指定的配置。本镜像内置的.bashrc会source$HOME下面的.configrc文件,可以在在里面自行设置。能达到安装的软件container分离, 在删除container时不删除安装的软件的目的

应用:用conda快速安装生信软件

各位在学习其他conda教程时,经常会学到conda create -n XXX新建一个运行环境以满足特定安装需求,还可以通过conda activate激活这个环境。

但其实还有一个参数-p用于指定安装目录,利用了这一点,我们就可以把自己dockerconda安装软件到非conda内部目录,而是映射过来的目录。如下

conda install -p /home/datasci/bioinfo -c bioconda roary

enter descriptiowork 就安装到对应的位置,如samtools,bcftools,varscan等一众生信软件都可以如此安装。 由于在.configrc里作了路径配置,这些软件即时能用! 在安装这些软件相应container被删除后,这些通过-p安装上的软件不会随着删除,下次重做container只要目录映射一致,不需要重装软件,不需要重装软件,不需要重装软件

TODO

  • jupyter_lab 2.3.0+
  • nginx config
  • python2.7-dev
  • nginx install
  • code-server 3.7.2+

BUGS

  1. conda安装的并激活一个环境中,报和libcurl.so相关的错误

把你对应目录下的 lib/libcurl.so.4给删除掉,或者从 /usr/lib/x86_64-linux-gnu下链接过来

  1. 最近发现jupyter lab升级后,装插件后会显示异常 发现是build过程中的问题,要性能强的服务器才能顺利完成这个工作。

  2. 安装tidyvers包出问题 google后发现问题出在haven和reaxl包上, 在R脚本里用下面方法解决

withr::with_makevars(c(PKG_LIBS = "-liconv"), install.packages("haven"), assignment = "+=")
withr::with_makevars(c(PKG_LIBS = "-liconv"), install.packages("readxl"), assignment = "+=")

leoatchina-datasci's People

Contributors

leoatchina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

leoatchina-datasci's Issues

你好,这个镜像很有用,感谢!但是好像jupyter lab没有启动

useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:bcPRVUAgJwLoK2QIA0oi0gC+veuah+bGXIrmtH4iBvQ root@9dd5a5c2247a (RSA)
Creating SSH2 DSA key; this may take some time ...
1024 SHA256:azpuSP5XJDxEwvTsijeMo/3VZvPjZPSryUHQ4/GWuC0 root@9dd5a5c2247a (DSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:6LCbDauThAk5AP5XL+7TMz4NWBsyGz0MfSGBtTXWFZ4 root@9dd5a5c2247a (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:fKy6FkVcfynyNjVOHjCr9pUw8NCNS+9XeWK0VfZbhVc root@9dd5a5c2247a (ED25519)
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of restart.

========================= starting services with USER datasci whose UID is 23333 ================================
rstudio-server.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install enable rstudio-server

  • Restarting RStudio Server rserver
    ...done.
    2019-10-12 23:03:55,117 CRIT Supervisor running as root (no user in config file)
    2019-10-12 23:03:55,119 INFO supervisord started with pid 145
    2019-10-12 23:03:56,123 INFO spawned: 'code-server' with pid 184
    2019-10-12 23:03:56,125 INFO spawned: 'sshd' with pid 185
    2019-10-12 23:03:57,804 INFO success: code-server entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
    2019-10-12 23:03:57,804 INFO success: sshd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

TODO

  • Add https support for codeserver.
    • using Caddy ? Since codeserver3.5 not support ssl, using 3.4.1 instead
  • 2 versions using R 3.6.3 or R 4.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.