Skip to content

Instantly share code, notes, and snippets.

@tianon
Last active June 17, 2020 23:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tianon/70958cd43668db8a317a to your computer and use it in GitHub Desktop.
Save tianon/70958cd43668db8a317a to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
str='docker run'
str+=' {{printf "--name=%q" .Name}}'
str+='{{if (eq .HostConfig.NetworkMode "bridge")}} {{printf "--hostname=%q" .Config.Hostname}}{{else}} {{printf "--net=%q" .HostConfig.NetworkMode}}{{end}}'
str+='{{if .Config.OpenStdin}} --interactive{{end}}'
str+='{{if .Config.Tty}} --tty{{end}}'
str+='{{if .Config.Memory}} {{printf "--memory=%.0f" .Config.Memory}}{{end}}'
str+='{{if .Config.CpuShares}} {{printf "--cpu-shares=%.0f" .Config.CpuShares}}{{end}}'
str+='{{range .Config.Env}} {{printf "--env=%q" .}}{{end}}'
str+='{{range .HostConfig.Binds}} {{printf "--volume=%q" .}}{{end}}'
str+='{{range .HostConfig.Dns}} {{printf "--dns=%q" .}}{{end}}'
str+='{{range .HostConfig.Devices}} {{printf "--device=%q:%q:%q" .PathOnHost .PathInContainer .CgroupPermissions}}{{end}}'
str+='{{if .Config.Entrypoint}} --entrypoint=""{{end}} {{.Config.Image}}{{range .Config.Entrypoint}} {{printf "%q" .}}{{end}}{{range .Config.Cmd}} {{printf "%q" .}}{{end}}'
exec docker inspect -f "$str" "$@"
@tianon
Copy link
Author

tianon commented Jun 17, 2020

For my own future reference, export DOCKER_API_VERSION=1.19 makes this script roughly work on Docker 19.03. 😅

(Enough to get the gist to recreate a proper script or compose blurb.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment