分享 用 Docker 启动 sandbox

Rei · June 11, 2017 · Last by linjunpop replied at June 25, 2017 · 2582 hits

有时需要临时 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 ...

Reply to luikore

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

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

Reply to 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,大大提高下载速度

You need to Sign in before reply, if you don't have an account, please Sign up first.