当网络模式设置为Container时,这个container将完全复用另外一个container的网络堆栈。同时使用时这个container的名称必须要符合下面的格式:--net container:<name|id>.
比如当前有一个绑定了本地地址localhost的redis container。如果另外一个container需要复用这个网络堆栈,则需要如下操作:
#docker run -d --name redis example/redis--bind 127.0.0.1
$ # use the redis container's network stackto access localhost
#sudo docker run --rm -ti --netcontainer:redis example/redis-cli -h 127.0.0.1 --oom-kill-disable
--oom-kill-disable=false Disable OOM Killer -P, --publish-all
-P, --publish-all=false Publish all exposed ports to random ports
对外映射所有端口。 -p, --publish
-p, --publish=[] Publish a container's port(s) to the host
对外映射指定端口,如不指定映射后的端口将随机指定。
#docker run –d -p 10022:22 -p 10080:80 -itwebserver:v1
使用docker run来启动我们创建的容器。-d让容器以后台方式运行。使用多个-p来映射多个端口,将容器的22端口映射为本地的10022,80映射为10080。 --pid
--pid= PID namespace to use
设置容器的PID模式。两种:
host: use the host's PID namespace insidethe container.
Note: the host mode gives the containerfull access to local PID and is therefore considered insecure. --privileged
--privileged=false Give extended privileges to this container
默认情况下container是不能访问任何其他设备的。但是通过"privileged",container就拥有了访问任何其他设备的权限。
当操作者执行docker run --privileged时,Docker将拥有访问host所有设备的权限
# docker run -it --rm --privilegedubuntu:14.04 /bin/bash --read-only
--read-only=false Mount the container's root filesystem asread only
启用后,容器的文件系统将为只读。
# docker run -it --rm --read-onlyubuntu:14.04 /bin/bash
root@d793e24f0af1:/# touch a
touch:cannot touch 'a': Read-only file system --restart
--restart=no Restart policy to apply when a containerexits
当容器退出或宿主机重启的时候,容器接着会重启操作。
重启策略:
no - 不重启
on-failure - container推出状态非0时重启
always - 始终重启
示例:
#docker run -it--restart=always ubuntu:14.04 /bin/bash
当退出容器时,再查看容器的状态为UP --rm
--rm=false Automatically remove the container whenit exits
容器退出时将自动销毁。 --security-opt
--security-opt=[] Security Options
安全选项。 --sig-proxy
--sig-proxy=true|false
Proxy received signals to the process(non-TTY mode only). SIGCHLD, SIGSTOP, and SIGKILL are not proxied. The defaultis true. --stop-signal
--stop-signal=SIGTERM Signal to stop a container, SIGTERM bydefault -t, --tty
-t, --tty=false Allocate a pseudo-TTY
分配一个模拟终端,常和-i一块使用. -u, --user
-u, --user= Username or UID (format:<name|uid>[:<group|gid>])
Sets the username or UID used andoptionally the groupname or GID for the specified command.
The followings examples are all valid:
--user [user | user:group | uid | uid:gid |user:gid | uid:group ]
Without this argument the command will berun as root in the container. --ulimit
--ulimit=[] Ulimit options
--default-ulimit,dockerdaemon的启动参数,能够指定默认container ulimit配置。如果此参数没配置,则默认从docker daemon继承;
--ulimit,docker run的参数,能够覆盖dockerdaemon指定的ulimit默认值。如果此参数没配置,则默认从default-ulimit继承;
# docker run -it -d --ulimitnofile=20480:40960 ubuntu:14.04 /bin/bash --uts
--uts= UTS namespace to use -v, --volume
-v, --volume=[] Bind mount a volume
可以使用带有 -v 参数的 docker run 命令给容器添加一个数据卷.
1.添加数据卷/data1,会自动创建目录
# docker run -it --name web -v /data1ubuntu:14.04 /bin/bash
root@fac11d44de3e:/# df -h
/dev/disk/by-uuid/1894172f-589b-4e8b-b763-7126991c7fbb 29G 2.6G 25G 10% /data1
root@fac11d44de3e:/# cd /data1
2.将宿主机的目录添加到容器
将宿主机的/data_web加载为容器/data目录
# docker run -it --name web -v/data_web:/data ubuntu:14.04 /bin/bash --volume-driver
--volume-driver= Optional volume driver for the container --volumes-from
--volumes-from=[] Mount volumes from the specifiedcontainer(s)
从其他容器挂载目录。
1.创建dbdata容器,并含有/data数据卷
# docker run -it -v /data --name dbdataubuntu:14.04 /bin/bash
2.创建webserver1挂载dbdata的数据卷
# docker run -it --volumes-from dbdata--name webserver1 ubuntu:14.04 /bin/bash -w, --workdir
-w, --workdir= Working directory inside the container
设置容器的工作目录。
# docker run -it--workdir="/data" ubuntu:14.04 /bin/bash
root@7868da4d2846:/data#