通过run命令创建一个新的容器(container)
命令格式:docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
参数选项说明
参数选项 | | 描述 |
| | 添加自定义主机到IP的映射 (格式:host:IP) ,例如: $ docker run --add-host=docker:10.180.0.1 --rm -it debian root@f38c87f2a42d:/# ping docker PING docker (10.180.0.1): 48 data bytes 56 bytes from 10.180.0.1: icmp_seq=0 ttl=254 time=7.600 ms |
| | 登录容器,关联到stdin stdout或stderr,例如:
|
| | Block IO(相对权重),介于10和1000之间,或0以禁用(默认为0 |
| | Block IO重量(相对设备重量) |
| | 添加权限 |
| | 删除权限 |
| | 容器的可选父cgroup |
| | 运行容器后,在指定文件中写入容器PID值,一种典型的监控系统用法 |
| | CPU计数(仅限Windows) |
| | CPU百分比(仅限Windows) |
| | 限制CPU CFS(完全公平调度程序)周期 |
| | 限制CPU CFS(完全公平调度程序)配额 |
| | 以微秒为单位限制CPU实时周期 |
| | 以微秒为单位限制CPU实时运行时间 |
| | 设置容器CPU权重,在CPU共享场景使用 |
| | 可以使用的CPU数目 |
| | 设置容器可以使用哪些CPU,此参数可以用来容器独占CPU (0-3, 0,1) |
| | MEMs in which to allow execution (0-3, 0,1) |
| | 指定容器运行于后台,并打印容器ID。其默认值为false |
| | Override the key sequence for detaching a container |
| | 添加主机设备给容器,相当于设备直通 |
| | Add a rule to the cgroup allowed devices list |
| | Limit read rate (bytes per second) from a device |
| | Limit read rate (IO per second) from a device |
| | Limit write rate (bytes per second) to a device |
| | Limit write rate (IO per second) to a device |
|
| Skip image verification |
| | 指定容器的dns服务器 |
| | Set DNS options |
| | Set DNS options |
| | 指定容器的dns搜索域名,写入到容器的/etc/resolv.conf文件 |
| | 覆盖image的入口点 |
| | 指定环境变量,容器中可以使用该环境变量 |
| | 指定环境变量文件,文件格式为每行一个环境变量 |
| | 指定容器暴露的端口,即修改镜像的暴露端口 |
| | Add additional groups to join |
| | Command to run to check health |
| | Time between running the check (ms|s|m|h) (default 0s) |
| | Consecutive failures needed to report unhealthy |
| | API 1.29+ Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s) |
| | Maximum time to allow one check to run (ms|s|m|h) (default 0s) |
| | Print usage |
| | 指定容器的主机名 |
| | API 1.25+ Run an init inside the container that forwards signals and reaps processes |
| | 打开STDIN,用于控制台交互。即使未连接,也保持stdin打开 |
| | Maximum IO bandwidth limit for the system drive (Windows only) |
| | Maximum IOps limit for the system drive (Windows only) |
| | IPv4 address (e.g., 172.30.100.104) |
| | IPv6 address (e.g., 2001:db8::33) |
| | IPC mode to use |
| | Container isolation technology |
| | Kernel memory limit |
| | Set meta data on a container |
| | Read in a line delimited file of labels |
| | 指定容器间的关联,使用其他容器的IP、env等信息 |
| | Container IPv4/IPv6 link-local addresses |
| | Logging driver for the container |
| | Log driver options |
| | Container MAC address (e.g., 92:d0:c6:0a:29:33) |
| | 指定容器的内存上限 |
| | 指定容器的内存软上限 |
| | Swap limit equal to memory plus swap: ‘-1’ to enable unlimited swap |
|
| Tune container memory swappiness (0 to 100) |
| | Attach a filesystem mount to the container |
| | 给容器分配名字,后续可以通过名字进行容器管理,links特性需要使用名字 |
| | 容器网络设置,链接容器到一个网络。有如下值:
|
| | Add network-scoped alias for the container |
| | Connect a container to a network |
| | Add network-scoped alias for the container |
| | Disable any container-specified HEALTHCHECK |
| | Disable OOM Killer |
| | Tune host’s OOM preferences (-1000 to 1000) |
| | PID namespace to use |
| | Tune container pids limit (set -1 for unlimited) |
| | experimental (daemon)API 1.32+ Set platform if server is multi-platform capable |
| | 指定容器是否为特权容器,特权容器拥有所有的capabilities |
| | 暴露容器的端口给主机 |
| | 将所有公开端口发布到随机端口 |
| | Mount the container’s root filesystem as read only |
|
| 指定容器停止后的重启策略:
|
| | 指定容器停止后自动删除容器 |
| | Runtime to use for this container |
| | Security Options |
| | Size of /dev/shm |
|
| 设置由代理接受并处理信号,但是SIGCHLD、SIGSTOP和SIGKILL不能被代理 |
|
| Signal to stop a container |
| | API 1.25+ Timeout (in seconds) to stop a container |
| | Storage driver options for the container |
| | Sysctl options |
| | Mount a tmpfs directory |
| | 分配tty设备,该可以支持终端登录,默认值为false |
| | Ulimit options |
| | 指定容器的用户或UID (格式: <name|uid>[:<group|gid>]) |
| | User namespace to use |
| | UTS namespace to use |
| | 给容器挂载存储卷,挂载到容器的某个目录 |
| | Optional volume driver for the container |
| | 给容器挂载其他容器上的卷,挂载到容器的某个目录 |
| | 指定容器里的工作目录 |
参考:
Docker官网英文版run命令描述
Docker命令详解(run篇)