| 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 |
stuzer05 / Docker inspect to run converter
Last active 3 months ago
`docker inspect` template to regenerate the `docker run` command that created a container, https://gist.github.com/efrecon/8ce9c75d518b6eb863f667442d7bc679, docker inspect --format "$(curl -s https://gist.stuzer.link/stuzer05/fdfc31107ce04720a186d409498e82f2/raw/HEAD/run.tpl)" 55a319b7e124
Revision 15a47c9058ecd8913d997eba7ee7199825aec533