Run command in stopped container

Containers are indeed process-centric. Once that process exits, the container is done. having the ability to commit is docker’s way of taking the resulting state from that process and preserving it.

This is a key difference between containers and say, a virtual machine.

Would you be willing to share a more specific use case that you are after? All the echo, tail, and sleep commands were just examples that may not illustrate a proper use case very clearly.

Data volumes in docker may be helpful for whatever your use case might be, for example.

Say I fire up a process in a container which will have some resulting data stored on that volume. Now, I want to fire up another container and use that data, I just have to attach the same volume. Here’s another made-up example:

$ docker run -v /host/path/to/volume:/vol ubuntu /bin/bash -c 'date | tee /vol/result.txt'
Tue Nov 11 07:07:11 UTC 2014
$ docker run -v /host/path/to/volume:/vol ubuntu /bin/bash -c 'cat /vol/result.txt'
Tue Nov 11 07:07:11 UTC 2014

More information on volumes here: