分享 用 Docker 启动 sandbox

Rei · 2017年06月11日 · 最后由 linjunpop 回复于 2017年06月25日 · 2579 次阅读

有时需要临时 pull 别人代码执行,但是在 host 环境执行有诸多风险,这时可以用 docker 启动一个沙箱环境:

$ docker run -it -v $(pwd):/app -w /app ruby:2.3 bash

不过这串命令太长了,反复输入几次之后我意识到可以写个 bash function:

# ~/.profile
sandbox() {
  docker run -it -v $(pwd):/app -w /app $1 bash
}

这样只要输入 sandbox ruby:2.3 就行了。

不过有些 image 没 bash ...

luikore 回复

一般不会用这么裸的镜像做 sandbox。

其实 ruby 有 safe 模式的,docker 如果用了 mount 对文件系统也会有影响

Rei 回复

Thanks. This article is important for me. Although I have been heard docker for a long time, it's the first time I use it. I suggest other developers try docker. It will only take you 5 minutes to have a new world. You can get a virtual machine totally no sweat.

Just follow https://store.docker.com/editions/community/docker-ce-desktop-mac and run

$ docker run -it -v $(pwd):/app -w /app ruby:2.3 bash , you will have a ruby2.3 container(like a debian virtual machine, but it will cost you only 19.27 MB's disk space).

顺便分享一个 Docker 的中国官方镜像 https://www.docker-cn.com/registry-mirror,大大提高下载速度

需要 登录 后方可回复, 如果你还没有账号请 注册新账号