Overview
NOTE! For running docker containers you must have docker engine installed. We assume that you already installed Docker.
Docker Containers
For running applications inside containers you will need a commad docker run
. Following format will help you understand running docker containers.
To Illustrate above command lets launch first container.
In above example
-
ubuntu - Is an image you run containers with. you are running command within Ubuntu OS. This image if not present locally is pulled from public image registry Docker Hub
-
/bin/echo - Is the command you run inside container running with specified image.
Docker Interactive Containers
In previous section containers remained active for the time of execution of command specified. So Let’s run the containers interactive manner.
To Illustrate above command lets run another container.
In above example
-
-t - Is the flag which assigns psuedo-tty or terminal inside container.
-
-i - Is the flag which allows you to run container interactively.
-
/bin/bash - Launches a bash shell inside container.
Lets run some more commands inside the same container
When completed, run the exit command or enter Ctrl-D to exit the interactive shell. This will also stop the running container.
Docker Daemonized Containers
If you want to run your application in daemonized way, you can do this in following manner
To Illustrate above command lets run a container
In above example
- -d - flag runs the container in the background (to daemonize it).
In this post we have studied three different ways to run containers.