split( String, A, [Ere] ): 将 String 参数指定的参数分割为数组元素 A[1], A[2], . . ., A[n],并返回 n 变量的值。此分隔可以通过 Ere 参数指定的扩展正则表达式进行, 或用当前字段分隔符(FS 特殊变量)来进行(如果没有给出 Ere 参数)。除非上下文指明特定的元素还应具有一个数字值,否则 A 数组中的元素用字符串值来创建。
split函数:以Ere分隔String并动态生成一个数组A(获取数组长度的方法,参考注意事项)。
substr( String, M, [ N ] ) :返回具有 N 参数指定的字符数量子串。子串从 String 参数指定的字符串取得,其字符以 M 参数指定的位置开始。M 参数指定为将 String 参数中的第一个字符作为编号 1。 如果未指定 N 参数,则子串的长度将是 M 参数指定的位置到 String 参数的末尾 的长度。
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
-a, --attach=[] Attach to STDIN, STDOUT or STDERR --add-host=[] Add a custom host-to-IP mapping (host:ip) --blkio-weight=0 Block IO weight (relative weight) --blkio-weight-device=[] Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`) --cpu-shares=0 CPU shares (relative 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-period=0 Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota=0 Limit CPU CFS (Completely Fair Scheduler) quota --cpuset-cpus="" CPUs in which to allow execution (0-3, 0,1) --cpuset-mems="" Memory nodes (MEMs) in which to allow execution (0-3, 0,1) -d, --detach Run container in background and print container ID --detach-keys Specify the escape key sequence used to detach a container --device=[] Add a host device to the container --device-read-bps=[] Limit read rate (bytes per second) from a device (e.g., --device-read-bps=/dev/sda:1mb) --device-read-iops=[] Limit read rate (IO per second) from a device (e.g., --device-read-iops=/dev/sda:1000) --device-write-bps=[] Limit write rate (bytes per second) to a device (e.g., --device-write-bps=/dev/sda:1mb) --device-write-iops=[] Limit write rate (IO per second) to a device (e.g., --device-write-bps=/dev/sda:1000) --disable-content-trust=true Skip image verification --dns=[] Set custom DNS servers --dns-opt=[] Set custom DNS options --dns-search=[] Set custom DNS search domains -e, --env=[] Set environment variables --entrypoint="" Overwrite the default ENTRYPOINT of the image --env-file=[] Read in a file of environment variables --expose=[] Expose a port or a range of ports --group-add=[] Add additional groups to run as -h, --hostname="" Container host name --help Print usage -i, --interactive Keep STDIN open even if not attached --ip="" Container IPv4 address (e.g. 172.30.100.104) --ip6="" Container IPv6 address (e.g. 2001:db8::33) --ipc="" IPC namespace to use --isolation="" Container isolation technology --kernel-memory="" Kernel memory limit -l, --label=[] Set metadata on the container (e.g., --label=com.example.key=value) --label-file=[] Read in a file of labels (EOL delimited) --link=[] Add link to another container --log-driver="" Logging driver for container --log-opt=[] Log driver specific options -m, --memory="" Memory limit --mac-address="" Container MAC address (e.g. 92:d0:c6:0a:29:33) --memory-reservation="" Memory soft limit --memory-swap="" A positive integer equal to memory plus swap. Specify -1 to enable unlimited swap. --memory-swappiness="" Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. --name="" Assign a name to the container --net="bridge" Connect a container to a network 'bridge': create a network stack on the default Docker bridge 'none': no networking 'container:<name|id>': reuse another container's network stack 'host': use the Docker host network stack '<network-name>|<network-id>': connect to a user-defined network --net-alias=[] Add network-scoped alias for the container --oom-kill-disable Whether to disable OOM Killer for the container or not --oom-score-adj=0 Tune the host's OOM preferences for containers (accepts -1000 to 1000) -P, --publish-all Publish all exposed ports to random ports -p, --publish=[] Publish a container's port(s) to the host --pid="" PID namespace to use --pids-limit=-1 Tune container pids limit (set -1 for unlimited), kernel >= 4.3 --privileged Give extended privileges to this container --read-only Mount the container's root filesystem as read only --restart="no" Restart policy (no, on-failure[:max-retry], always, unless-stopped) --rm Automatically remove the container when it exits --shm-size=[] Size of `/dev/shm`. The format is `<number><unit>`. `number` must be greater than `0`. Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you omit the unit, the system uses bytes. If you omit the size entirely, the system uses `64m`. --security-opt=[] Security Options --sig-proxy=true Proxy received signals to the process --stop-signal="SIGTERM" Signal to stop a container -t, --tty Allocate a pseudo-TTY -u, --user="" Username or UID (format: <name|uid>[:<group|gid>]) --userns="" Container user namespace 'host': Use the Docker host user namespace '': Use the Docker daemon user namespace specified by `--userns-remap` option. --ulimit=[] Ulimit options --uts="" UTS namespace to use -v, --volume=[host-src:]container-dest[:<options>] Bind mount a volume. The comma-delimited `options` are [rw|ro], [z|Z], [[r]shared|[r]slave|[r]private], and [nocopy]. The 'host-src' is an absolute path or a name value. --volume-driver="" Container's volume driver --volumes-from=[] Mount volumes from the specified container(s) -w, --workdir="" Working directory inside the container
上面的手册可以使用“docker run –help”或者到Docker官网查看。 run用于在新容器中执行一条命令,首先会创建一个新容器然后执行一条指令,其实这里包含了create、start以及exec命令的作用。 基本用法是:“docker run [OPTIONS] IMAGE [COMMAND] [ARG…]” 注:
可选选项OPTIONS:run具有丰富的选项,可以设置容器的一些特性
IMAGE:指定容器运行的基础镜像
可选命令COMMAND:容器运行时执行的命令
可选参数ARG:命令带的参数
基础用法
指定容器名并分配伪终端
1 2 3
$ docker run --name hello -it ubuntu root@a37b3b659c24:/# root@a37b3b659c24:/#
创建一个名字为hello的容器,并且分配一个伪终端,-i链接到容器的STDIN。
获取容器ID(–cidfile)
1 2 3 4 5 6
$ docker run --cidfile ./test.cid --name hello ubuntu $ cat test.cid b504823b5a2d281e0f8ee329e14a8052bbeb171f7e50720fe0dab98ebd75587fV2R1C00B003 $ docker run --cidfile ./test.cid --name hello ubuntu docker: Container ID file found, make sure the other container isn't running or delete ./test.cid. See 'docker run --help'.
通过–cidfile指定写入容器ID的文件路径,如果test.cid文件存在,命令会返回错误。
特权容器
1 2 3
$ docker run -t -i --rm ubuntu bash root@bc338942ef20:/# mount -t tmpfs none /mnt mount: permission denied
--volume=[host-src:]container-dest[:<options>] Bind mount a volume. The comma-delimited `options` are [rw|ro], [z|Z], [[r]shared|[r]slave|[r]private], and [nocopy]. The 'host-src' is an absolute path or a name value.
可以把host上的文件或者目录透传到容器内指定路径,例如:
1 2
$ docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd $ docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v /path/to/static-docker-binary:/usr/bin/docker busybox sh
Return low-level information on a container or image
-f, --format="" Format the output using the given go template --help Print usage --type=container|image Return JSON for_specified_type, permissible values are "image" or "container" -s, --size Display total file sizes if the type is container
format命令默认会把结果以JSON格式输出。 注意:
默认情况下,当容器名和镜像名相同时,format会输容器的结果
当时如果指定了–format,format会返回两个的格式化结果
关于–format选项可以参考Go语言的模板,这里只介绍简单的用法,例如获取容器的ID:
1
docker inspect -f='{ {.Id} }' haozi
获取Docker版本信息
1 2 3 4 5 6
Usage: docker version [OPTIONS]
Show the Docker version information.
-f, --format="" Format the output using the given go template --help Print usage
-f, --force Force the removal of a running container (uses SIGKILL) --help Print usage -l, --link Remove the specified link -v, --volumes Remove the volumes associated with the container
--detach-keys="<sequence>" Set up escape key sequence --help Print usage --no-stdin Do not attach STDIN --sig-proxy=true Proxy all received signals to the process
-d, --detach Detached mode: run commandin the background --detach-keys Specify the escape key sequence used to detach a container --help Print usage -i, --interactive Keep STDIN open even if not attached --privileged Give extended Linux capabilities to the command -t, --tty Allocate a pseudo-TTY -u, --user= Username or UID (format: <name|uid>[:<group|gid>])
-f, --follow Follow log output --help Print usage --since="" Show logs since timestamp -t, --timestamps Show timestamps --tail="all" Number of lines to show from the end of the logs
INFO Start processing FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html Template render error: (unknown path) [Line 191, Column 51] unexpected token: . at Object.exports.prettifyError (/blog/node_modules/nunjucks/src/lib.js:34:15) at new_cls.render (/blog/node_modules/nunjucks/src/environment.js:469:27) at new_cls.renderString (/blog/node_modules/nunjucks/src/environment.js:327:21) at /blog/node_modules/hexo/lib/extend/tag.js:66:9 at Promise._execute (/blog/node_modules/bluebird/js/release/debuggability.js:299:9) at Promise._resolveFromExecutor (/blog/node_modules/bluebird/js/release/promise.js:481:18) at new Promise (/blog/node_modules/bluebird/js/release/promise.js:77:14) at Tag.render (/blog/node_modules/hexo/lib/extend/tag.js:64:10) at Object.tagFilter [as onRenderEnd] (/blog/node_modules/hexo/lib/hexo/post.js:253:16) at /blog/node_modules/hexo/lib/hexo/render.js:65:19 at tryCatcher (/blog/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/blog/node_modules/bluebird/js/release/promise.js:510:31) at Promise._settlePromise (/blog/node_modules/bluebird/js/release/promise.js:567:18) at Promise._settlePromise0 (/blog/node_modules/bluebird/js/release/promise.js FROM node :612:10) at Promise._settlePromises (/blog/node_modules/bluebird/js/release/promise.js:691:18) at Async._drainQueue (/blog/node_modules/bluebird/js/release/async.js:138:16) at Async._drainQueues (/blog/node_modules/bluebird/js/release/async.js:148:10) at Immediate.Async.drainQueues (/blog/node_modules/bluebird/js/release/async.js:17:14) at runCallback (timers.js:649:20) at tryOnImmediate (timers.js:622:5) at processImmediate [as _immediateCallback] (timers.js:594:5) FATAL (unknown path) [Line 191, Column 51] unexpected token: . Template render error: (unknown path) [Line 191, Column 51] unexpected token: . at Object.exports.prettifyError (/blog/node_modules/nunjucks/src/lib.js:34:15) at new_cls.render (/blog/node_modules/nunjucks/src/environment.js:469:27) at new_cls.renderString (/blog/node_modules/nunjucks/src/environment.js:327:21) at /blog/node_modules/hexo/lib/extend/tag.js:66:9 at Promise._execute (/blog/node_modules/bluebird/js/release/debuggability.js:299:9) at Promise._resolveFromExecutor (/blog/node_modules/bluebird/js/release/promise.js:481:18) at new Promise (/blog/node_modules/bluebird/js/release/promise.js:77:14) at Tag.render (/blog/node_modules/hexo/lib/extend/tag.js:64:10) at Object.tagFilter [as onRenderEnd] (/blog/node_modules/hexo/lib/hexo/post.js:253:16) at /blog/node_modules/hexo/lib/hexo/render.js:65:19 at tryCatcher (/blog/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/blog/node_modules/bluebird/js/release/promise.js:510:31) at Promise._settlePromise (/blog/node_modules/bluebird/js/release/promise.js:567:18) at Promise._settlePromise0 (/blog/node_modules/bluebird/js/release/promise.js:612:10) at Promise._settlePromises (/blog/node_modules/bluebird/js/release/promise.js:691:18) at Async._drainQueue (/blog/node_modules/bluebird/js/release/async.js:138:16) at Async._drainQueues (/blog/node_modules/bluebird/js/release/async.js:148:10) at Immediate.Async.drainQueues (/blog/node_modules/bluebird/js/release/async.js:17:14) at runCallback (timers.js:649:20) at tryOnImmediate (timers.js:622:5) at processImmediate [as _immediateCallback] (timers.js:594:5)