Skip to content

Instantly share code, notes, and snippets.

@epishan
Forked from efrecon/run.tpl
Last active June 12, 2017 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epishan/50379826c04178226e43bbd03f8c5a8f to your computer and use it in GitHub Desktop.
Save epishan/50379826c04178226e43bbd03f8c5a8f to your computer and use it in GitHub Desktop.
[docker] `docker inspect` template to regenerate the `docker run` command that created a container
docker run \
--name={{.Name}} \
{{range $e := .Config.Env}}--env="{{$e}}" \
{{end}}{{range $p, $conf := .NetworkSettings.Ports}}-p {{(index $conf 0).HostIp}}:{{(index $conf 0).HostPort}}:{{$p}} \
{{end}}{{range $v := .HostConfig.VolumesFrom}}--volumes-from="{{.}}" \
{{end}}{{range $v := .HostConfig.Binds}}--volume="{{.}}" \
{{end}}{{range $l, $v := .Config.Labels}}--label "{{$l}}"="{{$v}}" \
{{end}}{{range $v := .HostConfig.CapAdd}}--cap-add {{.}} \
{{end}}{{range $v := .HostConfig.CapDrop}}--cap-drop {{.}} \
{{end}}{{range $d := .HostConfig.Devices}}--device={{(index $d).PathOnHost}}:{{(index $d).PathInContainer}}:{{(index $d).CgroupPermissions}} \
{{end}}{{range $v := .Config.Entrypoint}}--entrypoint="{{.}}" \
{{end}}{{with .HostConfig.LogConfig}}--log-driver="{{.Type}}" \
{{range $o, $v := .Config}}--log-opt {{$o}}="{{$v}}" \
{{end}}{{end}}{{with .HostConfig.RestartPolicy}}--restart="{{.Name}}{{if eq .Name "on-failure"}}{{.MaximumRetryCount}}{{end}}" \
{{end}}{{if .Config.Tty}}-t \
{{end}}{{if .Config.OpenStdin}}-i \
{{end}}{{if not (.Config.AttachStdout)}}--detach=true \
{{end}}{{if .HostConfig.Privileged}}--privileged \
{{end}}{{if .HostConfig.AutoRemove}}--rm \
{{end}}{{.Config.Image}} \
{{range .Config.Cmd}}{{.}} {{end}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment