I often find myself in need of re-creating container with minor modifications to arguments used to docker run
container originally (things like changing published ports, network, memory amount).
Now I am making images and running them in place of old containers.
This works fine but I don't always have original params to docker run
saved and sometimes (esp. when there are lot of things to define) it becomes pain to recover them.
Is there any way to recover docker run
arguments from existing container?
Sorry for being a couple of years late, but I had a similar question and no satisfying answer yet, so I still needed to find my way out.
I've found two sources addressing the issue:
To run, save this to a file, e.g.
run.tpl
and dodocker inspect --format "$(<run.tpl)" name_or_id_of_running_container
Quick run:
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod <container>
Both solutions are quite simple to use, but the second one failed to generate the command for an Nginx container because they did not manage to have it quoted like this "nginx" "-g" "daemon off;"
So, I focused on the first solution, which is a golang template intended to feed the --format
parameter of docker inspect
. I liked it because it was kind of simple, elegant, and no other tool needed.
I've made some improvements in my forked gist and notified the original author about it.
Couple of answers to this. Run your containers using docker-compose
, then you can just run compose files and retain all your configuration. Obviously compose is designed for multi-container applications, but massively underrated for single-container, complex run
argument use cases.
Second one is to put your run
command into a LABEL
on the image. Take a look at Label Schema's docker.cmd
etc... Then you can easily retrieve from the image (or from your Dockerfile).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With