Running an application
Running an application inside a container is done with docker run. For example
docker run ubuntu /bin/echo "hello world"
outputs hello world
In the command above we tell docker to run the image ubuntu and to run in the container /bin/echo and pass it as parameter "hello world". When the application is executed the container is shutdown.
What is the point?
Okay, I admit hello world isn't the world best example but the point is that we ran /bin/echo in the container and passed it on the parameter "hello world". It executed and once executed it exited the container.
As we saw in the previous post docker run -i -t ubuntu /bin/bash does basically the same thing. It runs /bin/bash within the container and it is only because /bin/bash isn't finished executing that the container doesn't stop.
Once your container has exited you can actually work with it again.
Will show you all running containers and
docker ps -a
Will show you all running and exited containers.
If you have a container that isn't of any use to you any more you can just use
To remove the container from the system.
Once you are getting the hang of it you will have a number of container with the status exited. To clean up my containers I use
docker ps -aq -f=exited | xargs docker rm