Last active
June 17, 2020 23:22
-
-
Save tianon/70958cd43668db8a317a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.)