r/LinuxTeck • u/Expensive-Rice-2052 • 4d ago
Docker Inspect Command: Reconstruct Docker Run Commands - Tip 134
Question: What's the original docker run command for this container?
Try: docker inspect nginx | jq -r '.[0] | "docker run -d --name \(.Name|ltrimstr("/")) -p \(.NetworkSettings.Ports|to_entries|.[0].value[0].HostPort):\(.NetworkSettings.Ports|to_entries|.[0].key|split("/")|.[0]) \(.Config.Image)"'
Info: Reconstructs a basic docker run command from inspect JSON.
Examples:
$ docker inspect $(docker ps -q) | jq -r '.[] | .Name' # List names of all running containers
$ docker history nginx # Inspect image build layers and commands
$ docker ps --format '{{.Names}}: {{.Status}}' # Show a compact status list of containers
Note: For containers with volumes, networks, env vars, or restart policies, `runlike` (`pip install runlike`) handles full reconstruction better than a one-liner. Store definitions in `docker-compose.yml` for repeatable deployments.
Want to master Linux one command at a time?
Follow r/LinuxTeck - 1 practical Linux tip every day. For more #LinuxTips click here https://www.linuxteck.com/linux-tips/