首页 > 其他 > 详细

docker-创建容器常见选项

时间:2019-11-26 13:16:28      阅读:97      评论:0      收藏:0      [点我收藏+]

1. docker run创建容器常见选项
 1.1 创建容器

选项 描述
-i,-interactive 交互式
-t,-tty 分配一个伪终端
-d,-detach 运行容器到后台
-e,-env 设置环境变量
-p(小写),-publish list 发布容器端口到主机
-P(大写),-publish -all 发布容器所有EXPOSE的端口到宿主机随机端口
--name string 指定容器名称
-h,-hostname 指定容器主机名
-ip string 指定容器IP,只能用于自定义网络
-network 连接容器到一个网络
-v,-volume list 绑定挂载一个卷
-restart string 容器退出时重启策略,默认no,可选值:【always|on-failure】

1. 2 容器资源限制

选项 描述
-m,--memory 容器可以使用的最大内存量
-memory-swap 允许交换到磁盘的内存量
-memory-swappiness=<0-100> 容器使用swap分区交换的百分比(0-100,默认为-1)                                   
--oom-kill-disable 禁止OOM killer
--cpus 可以使用的cpu数量
--cpuset-cpus 限制容器使用特定的cpu核心,如(0-3, 0,1)
--cpu-shares cpu共享(相对权重)

2. docker run 创建容器使用
  2.1 docker run -it创建一个容器,并进入容器

1 [root@test-2 ~]# docker run -it nginx

  2.2 docker run -d创建一个容器,并在后台运行

1 [root@test-1 playbooks]# docker run -it  -d nginx

  2.3 docker run -e创建一个容器,并设置环境变量

1 [root@test-1 playbooks]# docker run -it  -d  -e test=123456 nginx

  2.4 docker run -it -d -p80:80 创建一个容器,并设置本机端口对应容器端口

1 [root@test-1 playbooks]# docker run -it  -d  -p80:80 nginx

  2.5 docker run -it -name webnginx创建一个容器,并设置一个容器的名称

1 [root@test-1 playbooks]# docker run -it  -d  --name webnginx  nginx

  2.6 docker run -it -d -P(大写p)创建一个容器,并随机分配一个本机端口对应容器端口

1 [root@test-1 ~]# docker run -it -d --name web1 -P nginx

3. docker 容器资源限制
  3.1 案例1-内存限制-m参数,允许容器最多使用500M内存和100M的swap,并禁用OOM killer

1 [root@test-1 ~]# docker run -it -d --name nginx03 --memory="500m" --memory-swap="100m" --oom-kill-disable nginx
2 [root@test-1 ~]# docker stats nginx03     #查看运行状态

  3.2 cpu限额 ,允许容器最多使用一个的cpu

1 [root@test-1 ~]# docker run -it -d --name nginx04 --cpus="1" nginx
2 #允许容器最多使用50%的cpu
3 [root@test-1 ~]# docker run -it -d --name nginx05 --cpus=".5" nginx

 

docker-创建容器常见选项

原文:https://www.cnblogs.com/scajy/p/11934144.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!