Skip to content

Instantly share code, notes, and snippets.

@pomeo
Forked from efrecon/run.tpl
Last active September 24, 2024 09:32
Show Gist options
  • Save pomeo/690873a48e9f3ed55f0d57c7dbbe475c to your computer and use it in GitHub Desktop.
Save pomeo/690873a48e9f3ed55f0d57c7dbbe475c to your computer and use it in GitHub Desktop.
`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 $v := .HostConfig.CapAdd}}--cap-add {{.}} \
{{end}}{{range $v := .HostConfig.CapDrop}}--cap-drop {{.}} \
{{end}}{{with .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}}{{.Config.Image}} \
{{range .Config.Cmd}}{{.}} {{end}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment