Outfitting an IT training environment with Docker containers

Trainer Container

A Real-Life Case Study

We have been in the IT education and development field for more than a decade. The main objective of conducting technical training is to equip employees with bleeding edge technologies that meet current and future demands of businesses. Employees gain practical knowledge of the necessary skills before entering into real project or product development. The classes help employees become multiskilled professionals.

The training sessions train users on various streams of IT, such as system administration, product and application development, programming languages, and DevOps.

We typically train a large number of employees every month, so creating the necessary development environment and providing the necessary privileges for each user are major concerns because of the variety of technologies.

Also, it is always a challenge to monitor hands-on activities for online training participants. An instructor must monitor multiple participants simultaneously and debug a program in order to help participants work in different locations.

Our solution is to use the RHEL 7 platform to create a Docker system. An Ubuntu Docker image is used as a base image. From the base image, we have created custom Docker images catering to our training requirements, as shown in Figure 2.

Figure 2: A list of pre-built images.

Each image includes the necessary tools and documents, such as an editor, man pages, compilers, debuggers, performance monitoring tools, a list of lab exercises, and tasks for hands-on assessments. Instead of keeping all these items in a single image, we built each one targeted for a specific purpose, so that only the necessary packages are installed to keep the size optimal.

A shell script lets a system administrator automatically set up a batch of users. The automation script creates user accounts, sets passwords for each user, creates a container for every user, and modifies the .bash_profile for the new users, as shown in Figure 3. The sudo utility is not required for the user to start a Docker container.

Figure 3: Script for creating user accounts and containers.

The script in Figure 3 offers the option of choosing the number of containers you want to create. You can choose the Docker image from a list based on your specific training requirement. At the bottom of Figure 3, the command

useradd user$i

creates a user account. The i value represents the user number.

echo "user$i@123" | passwd --stdin user$i

sets the user password.

If the value of i is 1, the username will be created as user1 and the password will be set to user1@123 .

For a host system, we used a desktop computer with 8GB of RAM, an Intel Core i7 processor, and a 500GB hard disk to cater to infrastructure needs for technical trainings. In our experiment, we created 25 containers, and it took just 39 seconds, including creating 25 user accounts, setting passwords, and modifying user profile files.

To list all the user containers, you just need to execute the command:

$docker ps -a | grep user

The output of this command is shown in Figure 4. (The output just shows 10 of the 25 containers created.) Note that the container name is the same as the username to identify a running container with its user.

Figure 4: Details for 10 user containers.

To monitor the resource usage for all running containers, execute the command:

$docker stats
$(docker ps -a | grep user | awk '{print $NF}')

The docker stats command with container ID or name will print the computing resource utilization. To monitor container details for all users, list all the running containers (docker ps -a). You can then filter with only a user container name (grep user). To extract the container name of all users, cut the line with only the last field (awk '{print $NF}'), which is the container name. Pass this containers' names list to the docker stats command.

The resource utilization of 10 user containers is as shown in Figure 5. The displayed output is refreshed periodically. If you want to exit from the screen, press Ctrl+C.

Figure 5: Resource utilization for the 10 user containers.

To monitor the specific running container activities online (STDIN, STDOUT, and STDERR) as a system administrator, you can attach the container in your terminal by executing the command:

$docker attach <container name>

The command will attach your terminal with the running container, and you can view activities going on in the container. You can also take control of the container if you want to show a demo to the user. When you exit from the attached container, the running container also exits. Therefore, the user needs to log in again to get container access. To avoid this complication, first press Ctrl+P and then Ctrl+Q, which will detach your terminal without affecting the user's container.

To check the logfiles of the container in a server, whether it is running or stopped, you can get the log info by executing the command:

$docker logs <container name>

If you want to check in online without attaching the container, execute:

$docker logs -f <container name>

The -f option will continue streaming the new output from the container, although you cannot get control of the container when you use -f to attach the running container. To exit from the log screen, press Ctrl+C.

If you want to delete a specific container, use the command:

$docker rm <container name or ID>

If you want to delete all the existing containers, use the command:

$docker rm $(docker ps -a -q)

To clean up the system after the training session, use the script in Figure 6 to delete all user accounts, their home directories, and the related containers.

In Figure 6,

userdel user$i

deletes a user account, where i is the user number;

rm -rf /home/user$i

removes the user-related files and directories; and

var1=`docker ps -a | grep user$i | awk '{print $1}'`

lists all the existing containers (docker ps -a), filters the list for the user with user number i (grep user$i), and truncates the list to the first field only (awk '{print $1}') – the container ID – which is stored in the var1 variable. The final line,

docker rm $var1

removes the container with the given ID number.

Figure 6: A script for deleting user accounts and containers.


Providing lab infrastructure for hands-on exercises is a major challenge for technical training sites. Docker images let you easily create the containers you need to support a training class, and you can even give each user a personal container with root access.

Each running container provides an isolated environment from the host with independent root access for each participant. Monitoring users' systems in real time is possible through logfiles by using simple commands.

The creation of user accounts and allocation of containers for each user is automated through a shell script. After completion of the training sessions, you can delete the containers and user accounts with a shell script, as well. With some basic scripting and a little knowledge of Linux container technology, you can easily overcome the infrastructure challenge for supporting hands-on training.


  1. Docker Hub: https://hub.docker.com/
  2. The Docker Registry: http://hub.docker.com

The Author

Dr. B. Thangaraju received his Ph.D. in Physics and worked as a research associate at the Indian Institute of Science (IISc.), Bangalore, India, before joining Talent Transformation, Wipro Technologies. His core expertise lies in the Linux kernel, with knowledge of embedded, real-time Linux, open source software (OSS), and DevOps. He has published more than 55 papers on OSS and has presented 32 technical papers at national and international conferences. You can reach him at: mailto:balat.raju@wipro.com.

Rajesh Srivastava completed his computer engineering degree and currently serves as Social Officer for Talent Transformation at Wipro Technologies, Bangalore, India. He is an alumnus of Madan Mohan Malaviya University of Technology, Gorakhpur, India, and Stanford University, Stanford, California. He has been working in the IT industry for almost two decades. You can reach Rajesh at: mailto:rajesh.srivastava@wipro.com.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs

Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>


		<div class=