1

I'd like to know if there is a way to retrieve the "docker run" command which started a container ?

Because I'd like to add some parameters to a stopped container, I need to retrieve the original command, add my new parameters and start it.

Thank you for your help.

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
Fred Mériot
  • 3,439
  • 9
  • 27
  • 44

1 Answers1

1

If the only thing you want to change is the restart policy, you can now (in docker engine 1.11) use docker-update. docker-update can be applied to either a running or a stopped container, see man docker-update, eg:

# docker update --restart=unless-stopped containername

Some useful info is available in the output of docker ps, notably the port mappings, eg:

# docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                  NAMES
75d1e6adbb37        my-fancy-image      "/usr/sbin/sshd -D"   22 hours ago        Up 22 minutes       0.0.0.0:8022->22/tcp   fancy_torvalds

All the other command-line parameters that were used to start the container can be found in the output of docker inspect, eg:

# docker inspect containername
    ...
    "Path": "/usr/sbin/sshd",
    "Args": [
        "-D"
    ],
    ...
    "HostConfig": {
        "Binds": [
            "/home/user/workspace/thing:/home/other/workspace/thing"
        ],
    ...
        "PortBindings": {
            "22/tcp": [
                {
                    "HostIp": "",
                    "HostPort": "8022"
                }
            ]
        },
        "RestartPolicy": {
            "Name": "unless-stopped",
            "MaximumRetryCount": 0
        },
    ...

If it isn't just the restart policy you want to change (and you do have application data inside your container) you can save the container as an image, then run it as a new container. This should use no significant additional disk space. You don't need to push it to any repository:

# docker commit -m="Message" -a="Author Name" containername username/imagename:latest
# docker run <new options here> username/imagename:latest

I have to question why you want to do this at all. Do you have all your application data contained inside the same container as the application itself, making you reluctant to just delete the container and spin up a new one with your preferred options? There are many excellent discussions on this subject to be found, notably:

Community
  • 1
  • 1
Douglas Royds
  • 735
  • 5
  • 8
  • Because I'am lazy :) No, seriously it's just a question I ask to myself facing a container I started some weeks earlier with a long long line of boring parameters I did not save somewhere. And I'd just like to restart it with a restart policy. Thank you anyway ;) – Fred Mériot May 20 '16 at 09:51
  • Fair enough. Looks like docker update is the thing for you - if you're on engine 1.11 – Douglas Royds May 23 '16 at 00:04