Docker: kill/stop/restart a container, parameters maintained?

I run a specific docker image for the first time:

docker run [OPTIONS] image [CMD]

  • How to use port forwarding to connect to docker container using DNS name
  • How to recreate containers with Docker Compose on a Swarm Cluster of multiple nodes?
  • Put docker image into user local directory
  • Flask app doesn't retrieve data from same database as unit tests
  • BigTable docker image startup issue: util.NativeCodeLoader: Unable to load native-hadoop library for your platform
  • Reducing Disk I/O Rate of Containers
  • Some of the options I supply include --link (link with other containers) and -p (expose ports)

    I noticed that if I kill that container and simply do docker start <container-id>, Docker honors all the options that I specified during the run command including the links and ports.

    Is this behavior explicitly documented and can I always count on the start command to reincarnate the container with all the options I supplied in the run command?


    Also, I noticed that killing/starting a container which is linked to another container updates the upstream container’s /etc/hosts file automatically:

    A--(link)-->B (A has an entry in /etc/hosts for B)

    If I kill B, B will normally get a new IP address. I notice that when i start B, the entry for B in A’s /etc/hosts file is automatically updated… This is very nice.

    I read here that --link does not handle container restarts… Has this been updated recently? If not, why am I seeing this behavior?

    (Im using Docker version 1.7.1, build 786b29d)

  • Is there a way to replicate pwd in a volume mount for docker in a boot2docker context?
  • ImportError: cannot import name <package> in pods while restarting pod fixes
  • Unable to access Container url in Bluemix for Spring Boot Application
  • Do I really need docker swarm?
  • How to run NodeJS command-line tools inside Docker?
  • Docker nmap one container from inside another?
  • One Solution collect form web for “Docker: kill/stop/restart a container, parameters maintained?”

    Yes, things work as you describe 🙂

    You can rely on the behaviour of docker start as it doesn’t really “reincarnate” your container; it was always there on disk, just in a stopped state. It will also retain any changes to files, but changes in RAM, such as process state, will be lost. (Note that kill doesn’t remove a container, it just stops it with a SIGKILL rather than a SIGTERM, use docker rm to truly remove a container).

    Links are now updated when a container changes IP address due to a restart. This didn’t use to be the case. However, that’s not what the linked question is about – they are discussing whether you can replace a container with a new container of the same name and have links still work. This isn’t possible, but that scenario will be covered by the new networking functionality and “service” objects which is currently in the Docker experimental channel.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.