描述
docker create :创建一个新的容器但不启动它
用法
docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
选项
-a stdin: 指定标准输入输出内容类型,可选 STDIN/STDOUT/STDERR 三项;
-d: 后台运行容器,并返回容器ID;
-i: 以交互模式运行容器,通常与 -t 同时使用;
-P: 随机端口映射,容器内部端口随机映射到主机的端口
-p: 指定端口映射,格式为:主机(宿主)端口:容器端口
-t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
--name="nginx-lb": 为容器指定一个名称;
--dns 8.8.8.8: 指定容器使用的DNS服务器,默认和宿主一致;
--dns-search example.com: 指定容器DNS搜索域名,默认和宿主一致;
-h "mars": 指定容器的hostname;
-e username="ritchie": 设置环境变量;
--env-file=[]: 从指定文件读入环境变量;
--cpuset="0-2" or --cpuset="0,1,2": 绑定容器到指定CPU运行;
-m :设置容器使用内存最大值;
--net="bridge": 指定容器的网络连接类型,支持 bridge/host/none/container: 四种类型;
--link=[]: 添加链接到另一个容器;
--expose=[]: 开放一个端口或一组端口;
--volume , -v: 绑定一个卷
名称,简称 | 默认值 | 描述 |
--add-host | Add a custom host-to-IP mapping (host:ip) | |
--attach , -a | Attach to STDIN, STDOUT or STDERR | |
--blkio-weight | Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) | |
--blkio-weight-device | Block IO weight (relative device weight) | |
--cap-add | Add Linux capabilities | |
--cap-drop | Drop Linux capabilities | |
--cgroup-parent | Optional parent cgroup for the container | |
--cidfile | Write the container ID to the file | |
--cpu-count | CPU count (Windows only) | |
--cpu-percent | CPU percent (Windows only) | |
--cpu-period | Limit CPU CFS (Completely Fair Scheduler) period | |
--cpu-quota | Limit CPU CFS (Completely Fair Scheduler) quota | |
--cpu-rt-period | API 1.25+ Limit CPU real-time period in microseconds | |
--cpu-rt-runtime | API 1.25+ Limit CPU real-time runtime in microseconds | |
--cpu-shares , -c | CPU 共享 (relative weight) | |
--cpus | API 1.25+ CPU数量 | |
--cpuset-cpus | CPUs in which to allow execution (0-3, 0,1) | |
--cpuset-mems | MEMs in which to allow execution (0-3, 0,1) | |
--device | Add a host device to the container | |
--device-cgroup-rule | Add a rule to the cgroup allowed devices list | |
--device-read-bps | 读频率限制 (每秒字节数) | |
--device-read-iops | 读频率限制 (每秒输入输出) | |
--device-write-bps | 写频率限制 (每秒字节数) | |
--device-write-iops | 写频率限制 (每秒输入输出) | |
--disable-content-trust | true | 跳过镜像验证 |
--dns | 自定义DNS服务器 | |
--dns-opt | 设置DNS选项 | |
--dns-option | 设置DNS选项 | |
--dns-search | Set custom DNS search domains | |
--domainname | Container NIS domain name | |
--entrypoint | Overwrite the default ENTRYPOINT of the image | |
--env , -e | Set environment variables | |
--env-file | Read in a file of environment variables | |
--expose | Expose a port or a range of ports | |
--gpus | API 1.40+ GPU devices to add to the container (‘all’ to pass all GPUs) | |
--group-add | Add additional groups to join | |
--health-cmd | Command to run to check health | |
--health-interval | Time between running the check (ms|s|m|h) (default 0s) | |
--health-retries | Consecutive failures needed to report unhealthy | |
--health-start-period | API 1.29+ Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s) | |
--health-timeout | Maximum time to allow one check to run (ms|s|m|h) (default 0s) | |
--help | 帮助 | |
--hostname , -h | 容器主机名称 | |
--init | API 1.25+ Run an init inside the container that forwards signals and reaps processes | |
--interactive , -i | 时刻保持输入流打开 | |
--io-maxbandwidth | 最大系统输入输出带宽限制(仅限Windows) | |
--io-maxiops | 最大系统输入输出限制 (仅限Windows) | |
--ip | IPv4 地址 (示例, 172.30.100.104) | |
--ip6 | IPv6 地址 (示例, 2001:db8::33) | |
--ipc | 使用IPC模式 | |
--isolation | 容器隔离技术 | |
--kernel-memory | Kernel 内存限制 | |
--label , -l | 设置容器元数据 | |
--label-file | Read in a line delimited file of labels | |
--link | 连接其他容器 | |
--link-local-ip | Container IPv4/IPv6 link-local addresses | |
--log-driver | Logging driver for the container | |
--log-opt | Log driver options | |
--mac-address | 容器Mac地址 (例如, 92:d0:c6:0a:29:33) | |
--memory , -m | 内存限制 | |
--memory-reservation | 内存软限制 | |
--memory-swap | Swap limit equal to memory plus swap: ‘-1’ to enable unlimited swap | |
--memory-swappiness | -1 | Tune container memory swappiness (0 to 100) |
--mount | Attach a filesystem mount to the container | |
--name | 设置容器名称 | |
--net | 容器连接网络 | |
--net-alias | Add network-scoped alias for the container | |
--network | Connect a container to a network | |
--network-alias | Add network-scoped alias for the container | |
--no-healthcheck | Disable any container-specified HEALTHCHECK | |
--oom-kill-disable | Disable OOM Killer | |
--oom-score-adj | Tune host’s OOM preferences (-1000 to 1000) | |
--pid | PID 命名空间 | |
--pids-limit | Tune container pids limit (set -1 for unlimited) | |
--platform | experimental (daemon)API 1.32+ Set platform if server is multi-platform capable | |
--privileged | 开放容器扩展权限 | |
--publish , -p | 映射端口到主机 | |
--publish-all , -P | 随机开启主机端口到所有容器暴露端口 | |
--read-only | 容器根目录只读 | |
--restart | no | 容器存在时重启 |
--rm | 当容器存在时自动删除 | |
--runtime | Runtime to use for this container | |
--security-opt | 安全选项 | |
--shm-size | /dev/shm 容量 | |
--stop-signal | SIGTERM | 停止容器信号 |
--stop-timeout | API 1.25+ Timeout (in seconds) to stop a container | |
--storage-opt | Storage driver options for the container | |
--sysctl | Sysctl 选项 | |
--tmpfs | 挂载临时文件目录 | |
--tty , -t | 分配一个虚拟终端 | |
--ulimit | 无限参数 | |
--user , -u | 用户名 或 用户ID (格式: <name|uid>[:<group|gid>]) | |
--userns | 用户命名空间 | |
--uts | UTS命名空间 | |
--volume , -v | 绑定卷 | |
--volume-driver | 容器卷驱动 | |
--volumes-from | 绑定指定容器卷 | |
--workdir , -w | 容器内部工作目录 |
实例
创建启动容器
$ docker create -t -i fedora bash 6d8af538ec541dd581ebc2a24153a28329acb5268abe5ef868c1f1a261221752$ docker start -a -i 6d8af538ec5 bash-4.2#
绑定卷
$ docker create -v /data --name data ubuntu 240633dfbb98128fa77473d3d9018f6123b99c454b3251427ae190a7d951ad57$ docker run --rm --volumes-from data ubuntu ls -la /data total 8 drwxr-xr-x 2 root root 4096 Dec 5 04:10 .drwxr-xr-x 48 root root 4096 Dec 5 04:11 ..