Reputation: 788
I am not asking this question: See full command of running/stopped container in Docker
What I am asking is, if someone runs a docker container from the host with a command such as:
docker run --lots --of --mysterious --parameters --volumes --etc image-name
Is there some way for someone else to obtain the original command line in the host system that was used to create the container?
My guess is that no, that you would have to reconstruct it manually by putting together all information obtained from docker inspect
... but I may be wrong.
It seems there is no way to get this information from docker itself, but as explained in the comments below, you can always type history | grep "docker run"
and search for the one that launched the container.
Upvotes: 1
Views: 434
Reputation: 7734
Bash history often gets lost, e.g. after HISTSIZE is reached or when resizing your VM.
But indeed options can be retrieved through docker inspect
.
Here is an example. Actual bash command :
docker run -t -i --name my-osrm-image -v "/custom/path/to/data-osrm:/data" -p 80:5000 osrm/osrm-backend osrm-routed --algorithm mld /data/europe-latest.osrm
As you said, docker ps --no-trunc
(and -a
if the container is not running) may help but some information (e.g. directory bindings) will be missing.
However we can retrieved all the previous information from
docker inspect -f 'docker run --name {{.Name}} -v {{join .HostConfig.Binds " "}} -p {{.HostConfig.PortBindings}} {{.Config.Image}} {{join .Config.Cmd " "}}' my-osrm-image
This will output
docker run --name /my-osrm-image -v /custom/path/to/data-osrm:/data -p map[5000/tcp:[{ 80}]] osrm/osrm-backend osrm-routed --algorithm mld /data/europe-latest.osrm
It requires a bit of cleaning for the port binding but everything is there, and it can be extended to include further options accordingly with the docker inspect
JSON output. See also this documentation for the output formatting.
Upvotes: 1
Reputation: 2833
Marking the answer.
linux history would be the best way to get the docker command you had executed earlier.
Upvotes: 2