Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recover docker container's run arguments

Tags:

docker

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?

like image 714
Eugene Loy Avatar asked Mar 27 '17 17:03

Eugene Loy


2 Answers

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:

  • A gist

To run, save this to a file, e.g. run.tpl and do docker inspect --format "$(<run.tpl)" name_or_id_of_running_container

  • A docker image

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.

like image 97
Ictus Avatar answered Sep 19 '22 14:09

Ictus


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).

like image 31
johnharris85 Avatar answered Sep 22 '22 14:09

johnharris85