Introduction to Docker and Docker Toolbox

Introduction to Docker and Docker Toolbox
3 (60%) 4 votes

The article gives some knowledge about getting started and utilizing Docker containers. The focus is all about understanding  Docker and its basics. Once you start grasping the basics and learn to use them, you will easily understand how to use Docker with other products.

In this article, we are going to review the following points:

  1. Introduction to Docker
  2. Pre-requisites to be done for the installation
  3. Installation of Docker toolbox on Windows
  4. Basics on getting started with Docker
  5. Main docker commands to be used
  6. Methods to build Ubuntu images from the docker hub repository
  7. And much more…

Introduction

Docker is a portable, open platform, lightweight and simple to configure, build and split an operating system into small containers that can be used to deploy applications in isolated and secure containers.

These containers are designed to be portable so they can be shipped from one place to anotherю Thus, Docker is a tool that passes these containers to and from your systems. A container is a self-contained sealed unit of the required software. It has the combination of everything needed to run that code, as well as contains all the dependencies that your system needs bundled up in that container. Moreover, it even includes an operating system to run your code. So, it takes all the services that make up an operating system such as network configuration, storage, libraries, code, and IPC (Inter Process Communication) protocols.

Docker is built into a client-server application architecture. The Docker client initiates a request to a Docker daemon (Server). Both Docker client and Docker server can be run on the same or remote system.

Docker has a program, which builds containers from a code. It takes your code along with its dependencies, bundles it up, and seals into a container.

The tool is a good choice for DevOps pipeline to speed up the consistent delivery of applications. It offers a platform to streamline the development lifecycle by providing only required applications and services. Containers are great to be used for continuous integration and continuous delivery (CI/CD) workflows.

Install Docker Toolbox on Windows

For Windows 7 (or higher) operating systems, Docker provides Docker Toolbox, an installer with a platform to configure and launch a Docker environment. Additionally, it can set up and start a Docker environment on older Mac and Windows systems. Docker Toolbox installs a program known as Docker that helps manage Docker Virtual Machines and others components, including the VirtualBox, Docker Machine programs etc. Docker Toolbox also installs Docker Machine, which has several useful commands for managing the VMs (Virtual Machines).

The components of Docker Toolbox are as follows:

  1. Docker Machine
  2. Docker Engine
  3. Docker Compose
  4. Kinematic
  5. Docker Quickstart Terminal App
  6. Oracle VirtualBox

Prerequisites

Windows Operating System must be Windows OS 7 or higher – 64 bit with the enabled virtualization. You can check the virtualization technology in two different ways:

  • for Windows 8/8.1/10
    You can confirm the virtualization status in Task Manager -> Performance -> CPU tab.

Install Docker Toolbox

Installing Docker Toolbox on Windows is pretty straightforward. To download Docker Toolbox, select the Toolbox for windows button.

Locate the installer and follow the installation steps.

Double-click the executable file and click Next to continue.

Select a folder for the installation. Click Next.

Select the components to be installed and click Next.

Continue with the default additional tasks and click Next.

In the Setup – Docker Toolbox window, click Install to set up Docker toolbox.

Click Finish to exit the setup process. This indicates the successful installation of all the components.

That’s all…

As you can see, it is really simple to install the Docker toolbox.

Th next step is to launch the Docker Quickstart Terminal.

Getting Started

Let’s walk through the Docker commands. The Docker Flow is the fundamental concept of Docker. It all starts with an image, a file that makes up the operating system.

Open Docker Quickstart Terminal and run Docker commands.

The docker run command will download the “Hello world” container. Take a look at the Docker images using the Docker images command.

Now, execute the docker run command to invoke a Linux distro Ubuntu from a library. We can see the docker run command pulling the image from the library as it is unable to find an image locally.

The components of the command are as follows:

  1. it: Interactive terminal
  2. Ubuntu is the name of the image
  3. Latest is the tag which looks up to the latest repo from the library
  4. Bash is the shell to run with this image by default

To check what the container Linux distros is, use the cat command. To exit, type exit or press CTRL + D.

To list all the docker containers, type the following command.

a lists all the containers

Now, create a simple text file. The file size can be listed using the docker ps –s command.

-s displays the total file size.

For the demo, I have created another file named docker2. Invoke the docker ps –s command.

The size column displays an aggregation of the total files size.

The commands such as docker run and docker commit are complementary to each other. The docker run command takes images to containers while the docker commit command takes containers back to new images. Also, the docker run command creates a container from the image library.

Let’s verify the size of the Ubuntu container that should be 112 MB.

Next, build a new image from the Ubuntu container. As you can see, a few files have already been created on the container. Thus, we are going to install the wget utility on the Ubuntu container.

The container id is 6cb22da152ef. Let us create a new image with the container id.

The docker commit command requires the container ID as its parameter.

The output is an image ID that is different from the container ID. Thus, the new image is created from the original Ubuntu container.

The next step is to use the tag command to give a more meaningful name to the image.

To do this, copy the image ID, everything after the colon, and paste it as an argument to the docker tag command.

We received a new image called a docker image. Also, we can notice that the image size changes.

Next, run the docker image to see the files and use the wget utility to download a docker file.

We receive the docker.txt and docker2 files using the ls command.

Using the wget utility successfully downloaded the docker Ubuntu CE deb package.

We can start and stop the docker container using the docker start and stop commands.

The most important docker command is docker run. It takes a container out of the image and runs a process in that container. This is the main process of the container. When it ends, the container creation is successfully done.

Let’s see another command where lots of people use the container but don’t want to keep the container afterward. This can be done using the –rm options.

As we can see, there is a container entry 25e9e27cb114 in the docker process command. On exiting the console, the container automatically exits.

This section describes the steps to build images using docker files.

For the demo, perform the following steps:

  • Pull the CentOS image
  • Use the Vi text editor and type the text from the below screenshot
  • Build the test image received from mydockerfile

Run the following command to receive the image.

I would like to note that when I was trying to install the image to SQL Server docker on the docker container, the status column was the exited (1). Later when I noticed that it was not running, I could check what went wrong with docker logs.

For example, we execute the command below:

Let’s prepare a small script to remove the containers using bash scripting.

The container ID column is selected and passes an argument to it to remove the container.

Removing images using the pattern match

To list all the images, use the docker image –a command. If you want to find the images that match the specific pattern, use grep in combination with docker image. Now, select the IMAGE ID column and pass it as an argument to the docker rmi command.

Additionally, you can forcefully remove the image using the –f parameter.

Summary

This article is an effort to quickly give a glimpse of Docker containers. With the advent of Docker containers, developers can focus more on writing code without thinking about the underlying infrastructure which their code will be executed on. The Docker container-based platform facilitates the developers to test their workloads on local machines, remote servers, virtual machines or on the cloud. Also, the Docker images can be created and customized using a Docker file that, in turn, allows packaging only required components.

When speaking about the pros, I would like to note that the evolution of containers would speed up the entire SDLC (Software Development Life Cycle) process. It’s very helpful in testing and adopting agile practices due to its portability and lightweight nature.

That’s all for now…

Stay tuned for more updates! The Part 2 – Docker and SQL Server on Linux.

References

https://support.cmfirstgroup.com/hc/en-us/articles/115002363383-How-to-Create-and-Run-MS-SQL-Server-Docker-Container

https://docs.docker.com/toolbox/overview/

https://docs.docker.com/engine/reference/commandline/docker/

Prashanth Jayaram

Prashanth Jayaram

Prashanth Jayaram is working as a DB Manager for a leading MNC, Database Technologist, Author, Blogger, Automation Expert, Technet WIKI Ninja, and Powershell Geek.
Prashanth Jayaram