Skip to content

Instantly share code, notes, and snippets.

@jackyq2015
Forked from miracle2k/.bashrc
Created November 21, 2019 21:05
Show Gist options
  • Save jackyq2015/342cea7d26f8b0f90ad058b80d0c97ce to your computer and use it in GitHub Desktop.
Save jackyq2015/342cea7d26f8b0f90ad058b80d0c97ce to your computer and use it in GitHub Desktop.
Convert an existing docker container into a "docker run" command line
# Convert an existing docker container into a "docker run" command line.
#
# This is useful when trying to debug containers that have been created
# by orchestration tools.
#
# Install jq: stedolan.github.io/jq/
function format_run() {
cid=$1
json=$(docker inspect $cid 2>&1)
# parse container info
entrypoint=$( echo $json | jq -r '.[0].Config.Entrypoint | join(" ")' )
envvars=$( echo $json | jq -r '(.[0].Config.Env | [" -e " + .[]] | join(""))' )
image=$( echo $json | jq -r .[0].Image )
cmd=$( echo $json | jq -r '.[0].Config.Cmd | join(" ")' )
echo "docker run --entrypoint $entrypoint $envvars $image $cmd"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment