1. docker run创建容器常见选项
1.1 创建容器
1. 2 容器资源限制
1.docker exec进入容器
docker exec -it 容器ID /bin/bash
2. docker run 创建容器使用
docker run -it创建一个容器,并进入容器
[root@test-2 ~]# docker run -it nginx
2.2 docker run -d创建一个容器,并在后台运行
[root@test-1 playbooks]# docker run -it -d nginx
2.3 docker run -e创建一个容器,并设置环境变量
[root@test-1 playbooks]# docker run -it -d -e test=123456 nginx
2.4 docker run -it -d -p80:80 创建一个容器,并设置本机端口对应容器端口
[root@test-1 playbooks]# docker run -it -d -p80:80 nginx
2.5 docker run -it -name webnginx创建一个容器,并设置一个容器的名称
[root@test-1 playbooks]# docker run -it -d --name webnginx nginx
2.6 docker run -it -d -P(大写p)创建一个容器,并随机分配一个本机端口对应容器端口
[root@test-1 ~]# docker run -it -d --name web1 -P nginx
docker 容器资源限制
3.1 案例1-内存限制-m参数,允许容器最多使用500M内存和100M的swap,并禁用OOM killer
[root@test-1 ~]# docker run -it -d --name nginx03 --memory="500m" --memory-swap="100m" --oom-kill-disable nginx
[root@test-1 ~]# docker stats nginx03 #查看运行状态
3.2 cpu限额 ,允许容器最多使用一个的cpu
[root@test-1 ~]# docker run -it -d --name nginx04 --cpus="1" nginx
#允许容器最多使用50%的cpu
[root@test-1 ~]# docker run -it -d --name nginx05 --cpus=".5" nginx