Launching a container as a daemon

We already experimented with an interactive container, tracked the changes that were made to the containers, created images from the containers, and then gained insights in the containerization paradigm. Now, let's move on to understand the real workhorse of Docker technology. Yes that's right. In this section, we will walk you through the steps that are required for launching a container in detached mode; in other words, you will learn about the steps that are required for launching a container as a daemon. We will also view the text that is generated in the container.

The docker run subcommand supports the -d option, which will launch a container in detached mode, that is, it will launch a container as a daemon. For illustrating, let's resort to our date and time script, which we used in the pause/unpause container example, as shown here:

$ sudo docker run -d ubuntu 
/bin/bash -c "while true; do date; sleep 5; done"
0137d98ee363b44f22a48246ac5d460c65b67e4d7955aab6cbb0379ac421269b

The docker logs subcommand is used for viewing the output generated by our daemon container, as shown here:

$ sudo docker logs 
0137d98ee363b44f22a48246ac5d460c65b67e4d7955aab6cbb0379ac421269b
Sat Oct 4 17:41:04 UTC 2016
Sat Oct 4 17:41:09 UTC 2016
Sat Oct 4 17:41:14 UTC 2016
Sat Oct 4 17:41:19 UTC 2016
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset