Skip to content

Instantly share code, notes, and snippets.

@alexniver
Last active November 24, 2015 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexniver/2224707a29738dba7593 to your computer and use it in GitHub Desktop.
Save alexniver/2224707a29738dba7593 to your computer and use it in GitHub Desktop.
  1. docker run -it busybox sh ----启动一个continer, i表示允许发送数据,打开tty,效果就是可以使用命令行控制continer, sh表示运行continer之后直接执sh命令
  2. docker run -it --rm busybox sh ----rm表示continer停止后自动删除continer. docker每次run都会新建一个continer
  3. docker restart continerId -------根据continerid重启docker continer
  4. docker run -it --rm -v /home/tom/develop:/busybox/develop busybox sh------ -v /home/tom/develop:/busybox/develop busybox 映射本机文件夹(左边)到continer文件夹(右边), 如果两个文件夹都不存在,则会自动创建, 一个文件夹内创建的文件可以在另一个文件夹内看到. (PS:continer内创建文件,在本机内的权限会是root)
  5. docker run -it --rm -v /home/tom/develop:/busybox/develop -u 1000:1000 busybox sh------ -u 1000:1000 (用户id:组id), 此时如果在continer内创建文件, 本机内生成文件权限则为用户id为1000和组id为1000的用户
  6. docker run -d -p 80 nginx ----- -d表示demon,continer自动后台运行, -p 80 本机随机端口映射continer80端口(可以通过docker ps查看详细端口信息).
  7. docker run -d -p 8080:80 nginx ----- 本机8080端口映射continer 80端口
  8. docker run -it --rm -e http_proxy=http://127.0.0.1:8118 busybox sh ----- -e表示传递一个环境变量, 这里设置了http的代理
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment