run.tpl
· 4.7 KiB · Smarty
Raw
docker run \
--name {{printf "%q" .Name}} \
{{- with .HostConfig}}
{{- if .Privileged}}
--privileged \
{{- end}}
{{- if .AutoRemove}}
--rm \
{{- end}}
{{- if .Runtime}}
--runtime {{printf "%q" .Runtime}} \
{{- end}}
{{- range $b := .Binds}}
--volume {{printf "%q" $b}} \
{{- end}}
{{- range $v := .VolumesFrom}}
--volumes-from {{printf "%q" $v}} \
{{- end}}
{{- range $l := .Links}}
--link {{printf "%q" $l}} \
{{- end}}
{{- if index . "Mounts"}}
{{- range $m := .Mounts}}
--mount type={{.Type}}
{{- if $s := index $m "Source"}},source={{$s}}{{- end}}
{{- if $t := index $m "Target"}},destination={{$t}}{{- end}}
{{- if index $m "ReadOnly"}},readonly{{- end}}
{{- if $vo := index $m "VolumeOptions"}}
{{- range $i, $v := $vo.Labels}}
{{- printf ",volume-label=%s=%s" $i $v}}
{{- end}}
{{- if $dc := index $vo "DriverConfig" }}
{{- if $n := index $dc "Name" }}
{{- printf ",volume-driver=%s" $n}}
{{- end}}
{{- range $i, $v := $dc.Options}}
{{- printf ",volume-opt=%s=%s" $i $v}}
{{- end}}
{{- end}}
{{- end}}
{{- if $bo := index $m "BindOptions"}}
{{- if $p := index $bo "Propagation" }}
{{- printf ",bind-propagation=%s" $p}}
{{- end}}
{{- end}} \
{{- end}}
{{- end}}
{{- if .PublishAllPorts}}
--publish-all \
{{- end}}
{{- if .UTSMode}}
--uts {{printf "%q" .UTSMode}} \
{{- end}}
{{- with .LogConfig}}
--log-driver {{printf "%q" .Type}} \
{{- range $o, $v := .Config}}
--log-opt {{$o}}={{printf "%q" $v}} \
{{- end}}
{{- end}}
{{- with .RestartPolicy}}
--restart "{{.Name -}}
{{- if eq .Name "on-failure"}}:{{.MaximumRetryCount}}
{{- end}}" \
{{- end}}
{{- range $e := .ExtraHosts}}
--add-host {{printf "%q" $e}} \
{{- end}}
{{- range $v := .CapAdd}}
--cap-add {{printf "%q" $v}} \
{{- end}}
{{- range $v := .CapDrop}}
--cap-drop {{printf "%q" $v}} \
{{- end}}
{{- range $d := .Devices}}
--device {{printf "%q" (index $d).PathOnHost}}:{{printf "%q" (index $d).PathInContainer}}:{{(index $d).CgroupPermissions}} \
{{- end}}
{{- end}}
{{- with .NetworkSettings -}}
{{- range $p, $conf := .Ports}}
{{- with $conf}}
--publish "
{{- if $h := (index $conf 0).HostIp}}{{$h}}:
{{- end}}
{{- (index $conf 0).HostPort}}:{{$p}}" \
{{- end}}
{{- end}}
{{- range $n, $conf := .Networks}}
{{- with $conf}}
--network {{printf "%q" $n}} \
{{- range $a := $conf.Aliases}}
--network-alias {{printf "%q" $a}} \
{{- end}}
{{- end}}
{{- end}}
{{- end}}
{{- with .Config}}
{{- if .Hostname}}
--hostname {{printf "%q" .Hostname}} \
{{- end}}
{{- if .Domainname}}
--domainname {{printf "%q" .Domainname}} \
{{- end}}
{{- if index . "ExposedPorts"}}
{{- range $p, $conf := .ExposedPorts}}
--expose {{printf "%q" $p}} \
{{- end}}
{{- end}}
{{- if .User}}
--user {{printf "%q" .User}} \
{{- end}}
{{- range $e := .Env}}
--env {{printf "%q" $e}} \
{{- end}}
{{- range $l, $v := .Labels}}
--label {{printf "%q" $l}}={{printf "%q" $v}} \
{{- end}}
{{- if not (or .AttachStdin (or .AttachStdout .AttachStderr))}}
--detach \
{{- end}}
{{- if .AttachStdin}}
--attach stdin \
{{- end}}
{{- if .AttachStdout}}
--attach stdout \
{{- end}}
{{- if .AttachStderr}}
--attach stderr \
{{- end}}
{{- if .Tty}}
--tty \
{{- end}}
{{- if .OpenStdin}}
--interactive \
{{- end}}
{{- if .Entrypoint}}
{{- /* Since the entry point cannot be overridden from the command line with an array of size over 1,
we are fine assuming the default value in such a case. */ -}}
{{- if eq (len .Entrypoint) 1 }}
--entrypoint "
{{- range $i, $v := .Entrypoint}}
{{- if $i}} {{end}}
{{- $v}}
{{- end}}" \
{{- end}}
{{- end}}
{{printf "%q" .Image}} \
{{range .Cmd}}{{printf "%q " .}}{{- end}}
{{- end}}
| 1 | docker run \ |
| 2 | --name {{printf "%q" .Name}} \ |
| 3 | {{- with .HostConfig}} |
| 4 | {{- if .Privileged}} |
| 5 | --privileged \ |
| 6 | {{- end}} |
| 7 | {{- if .AutoRemove}} |
| 8 | --rm \ |
| 9 | {{- end}} |
| 10 | {{- if .Runtime}} |
| 11 | --runtime {{printf "%q" .Runtime}} \ |
| 12 | {{- end}} |
| 13 | {{- range $b := .Binds}} |
| 14 | --volume {{printf "%q" $b}} \ |
| 15 | {{- end}} |
| 16 | {{- range $v := .VolumesFrom}} |
| 17 | --volumes-from {{printf "%q" $v}} \ |
| 18 | {{- end}} |
| 19 | {{- range $l := .Links}} |
| 20 | --link {{printf "%q" $l}} \ |
| 21 | {{- end}} |
| 22 | {{- if index . "Mounts"}} |
| 23 | {{- range $m := .Mounts}} |
| 24 | --mount type={{.Type}} |
| 25 | {{- if $s := index $m "Source"}},source={{$s}}{{- end}} |
| 26 | {{- if $t := index $m "Target"}},destination={{$t}}{{- end}} |
| 27 | {{- if index $m "ReadOnly"}},readonly{{- end}} |
| 28 | {{- if $vo := index $m "VolumeOptions"}} |
| 29 | {{- range $i, $v := $vo.Labels}} |
| 30 | {{- printf ",volume-label=%s=%s" $i $v}} |
| 31 | {{- end}} |
| 32 | {{- if $dc := index $vo "DriverConfig" }} |
| 33 | {{- if $n := index $dc "Name" }} |
| 34 | {{- printf ",volume-driver=%s" $n}} |
| 35 | {{- end}} |
| 36 | {{- range $i, $v := $dc.Options}} |
| 37 | {{- printf ",volume-opt=%s=%s" $i $v}} |
| 38 | {{- end}} |
| 39 | {{- end}} |
| 40 | {{- end}} |
| 41 | {{- if $bo := index $m "BindOptions"}} |
| 42 | {{- if $p := index $bo "Propagation" }} |
| 43 | {{- printf ",bind-propagation=%s" $p}} |
| 44 | {{- end}} |
| 45 | {{- end}} \ |
| 46 | {{- end}} |
| 47 | {{- end}} |
| 48 | {{- if .PublishAllPorts}} |
| 49 | --publish-all \ |
| 50 | {{- end}} |
| 51 | {{- if .UTSMode}} |
| 52 | --uts {{printf "%q" .UTSMode}} \ |
| 53 | {{- end}} |
| 54 | {{- with .LogConfig}} |
| 55 | --log-driver {{printf "%q" .Type}} \ |
| 56 | {{- range $o, $v := .Config}} |
| 57 | --log-opt {{$o}}={{printf "%q" $v}} \ |
| 58 | {{- end}} |
| 59 | {{- end}} |
| 60 | {{- with .RestartPolicy}} |
| 61 | --restart "{{.Name -}} |
| 62 | {{- if eq .Name "on-failure"}}:{{.MaximumRetryCount}} |
| 63 | {{- end}}" \ |
| 64 | {{- end}} |
| 65 | {{- range $e := .ExtraHosts}} |
| 66 | --add-host {{printf "%q" $e}} \ |
| 67 | {{- end}} |
| 68 | {{- range $v := .CapAdd}} |
| 69 | --cap-add {{printf "%q" $v}} \ |
| 70 | {{- end}} |
| 71 | {{- range $v := .CapDrop}} |
| 72 | --cap-drop {{printf "%q" $v}} \ |
| 73 | {{- end}} |
| 74 | {{- range $d := .Devices}} |
| 75 | --device {{printf "%q" (index $d).PathOnHost}}:{{printf "%q" (index $d).PathInContainer}}:{{(index $d).CgroupPermissions}} \ |
| 76 | {{- end}} |
| 77 | {{- end}} |
| 78 | {{- with .NetworkSettings -}} |
| 79 | {{- range $p, $conf := .Ports}} |
| 80 | {{- with $conf}} |
| 81 | --publish " |
| 82 | {{- if $h := (index $conf 0).HostIp}}{{$h}}: |
| 83 | {{- end}} |
| 84 | {{- (index $conf 0).HostPort}}:{{$p}}" \ |
| 85 | {{- end}} |
| 86 | {{- end}} |
| 87 | {{- range $n, $conf := .Networks}} |
| 88 | {{- with $conf}} |
| 89 | --network {{printf "%q" $n}} \ |
| 90 | {{- range $a := $conf.Aliases}} |
| 91 | --network-alias {{printf "%q" $a}} \ |
| 92 | {{- end}} |
| 93 | {{- end}} |
| 94 | {{- end}} |
| 95 | {{- end}} |
| 96 | {{- with .Config}} |
| 97 | {{- if .Hostname}} |
| 98 | --hostname {{printf "%q" .Hostname}} \ |
| 99 | {{- end}} |
| 100 | {{- if .Domainname}} |
| 101 | --domainname {{printf "%q" .Domainname}} \ |
| 102 | {{- end}} |
| 103 | {{- if index . "ExposedPorts"}} |
| 104 | {{- range $p, $conf := .ExposedPorts}} |
| 105 | --expose {{printf "%q" $p}} \ |
| 106 | {{- end}} |
| 107 | {{- end}} |
| 108 | {{- if .User}} |
| 109 | --user {{printf "%q" .User}} \ |
| 110 | {{- end}} |
| 111 | {{- range $e := .Env}} |
| 112 | --env {{printf "%q" $e}} \ |
| 113 | {{- end}} |
| 114 | {{- range $l, $v := .Labels}} |
| 115 | --label {{printf "%q" $l}}={{printf "%q" $v}} \ |
| 116 | {{- end}} |
| 117 | {{- if not (or .AttachStdin (or .AttachStdout .AttachStderr))}} |
| 118 | --detach \ |
| 119 | {{- end}} |
| 120 | {{- if .AttachStdin}} |
| 121 | --attach stdin \ |
| 122 | {{- end}} |
| 123 | {{- if .AttachStdout}} |
| 124 | --attach stdout \ |
| 125 | {{- end}} |
| 126 | {{- if .AttachStderr}} |
| 127 | --attach stderr \ |
| 128 | {{- end}} |
| 129 | {{- if .Tty}} |
| 130 | --tty \ |
| 131 | {{- end}} |
| 132 | {{- if .OpenStdin}} |
| 133 | --interactive \ |
| 134 | {{- end}} |
| 135 | {{- if .Entrypoint}} |
| 136 | {{- /* Since the entry point cannot be overridden from the command line with an array of size over 1, |
| 137 | we are fine assuming the default value in such a case. */ -}} |
| 138 | {{- if eq (len .Entrypoint) 1 }} |
| 139 | --entrypoint " |
| 140 | {{- range $i, $v := .Entrypoint}} |
| 141 | {{- if $i}} {{end}} |
| 142 | {{- $v}} |
| 143 | {{- end}}" \ |
| 144 | {{- end}} |
| 145 | {{- end}} |
| 146 | {{printf "%q" .Image}} \ |
| 147 | {{range .Cmd}}{{printf "%q " .}}{{- end}} |
| 148 | {{- end}} |
| 149 |