Reputation: 4357
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.
Upvotes: 1
Views: 423
Reputation: 905
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:
Upvotes: 1