Docker for beginners tutorial:

by Apr 21, 2020Python

What is Docker?

Docker, in simple words is a tool that allows developers who build applications, to package them with all their dependencies into a ‘container’ which can easily be shipped to run on the host operating . Containers do not have high overhead and allow more efficient use of system and resources. Develop, ship and run are often heard Docker keywords and makes deploying an application far simpler. In this Docker tutorial, we’ll go through some of the basic blocks of Docker and how to begin to understand them.

What are containers and why should we use them?

Applications, in general, are deployed using VMs. These Virtual Machines essentially run applications on virtual hardware powered by the server’s host OS. VMs can provide full process isolation for applications. This means that a problem in the host OS does not affect the software, or vice-versa. But, the downside to this is computational overhead is quite a lot.

Containers on the other hand, provide most of the isolation at a much lower computing power cost. Which allows container-based applications to be deployed easily and consistently, owing to the predictability of the environment on which it will be run.

Containerization is bringing abstraction to the OS level. Whereas, virtualization brings abstraction to the hardware.

Installing Docker onto your computer:

I have a Windows Computer. So, I’m going to be guiding you through the process to install docker on the Windows platform. But in the chance you use MAC or Linux – don’t worry. The process is similar and fairly simple, for which you can follow the tutorials on the official page – for MAC and Linux

  1. Download Docker from the Docker Hub

2. Install Docker Desktop on Windows by double-clicking on Docker Desktop Installer.exe to run the installer. Then follow the instructions on the installation wizard.

3. Click Finish on the setup complete dialog and launch the Docker Desktop application.

4. Start Docker by searching and selecting Docker Desktop. When the whale icon in the status bar stays steady it is ready to be used.

To test that it runs properly, we can use the run command to download and run a simple HelloWorld Docker container. Which will download the hello-world image, and run it as a container.

sudo docker run hello-world

If you want to run the Ubuntu OS on Windows, you can download the Ubuntu Image by typing

docker run –it Ubuntu bash

Docker Hub

Docker Hub is a service on the cloud which lets the user download Docker images built by others. You can also upload your own Docker built images to the hub. Click here to go to the official Docker hub site

Step 1 : Sign-up on Docker hub.

Step 2 − Log into Docker Hub and you will be able to see the repositories

Step 3 − Next, let’s browse and find the image you want, for example the Jenkins image

Step 4 – Scroll and find the Docker pull command. Which can be used to download the Jenkins image onto the local Ubuntu server.

Step 5 − Run the following command:

sudo docker pull jenkins

To run Jenkins as a container on the Ubuntu machine., you need to run the following command.

sudo docker run -p 8080:8080 -p 50000:50000 jenkins

Docker – Images

An image is a combination of a file system and parameters, and forms the basis in Docker.

Displaying Docker Images

To display the list of all the images currently installed on the system, you can issue the following command.

sudo docker images

When we run the above command, it will produce something like the above. This server has three images: centos, newcentos, and jenkins. Each image has:

  • TAG − This is used to logically tag images.
  • Image ID − This is used to uniquely identify the image.
  • Created − The number of days since the image was created.
  • Virtual Size − The size of the image.

Downloading Docker Images

Images can be downloaded from Docker Hub using the Docker run command. Let’s see in detail how we can do this. For instance to download the centos image, and run the container:

sudo docker run centos

You will now see the CentOS Docker image downloaded. Now, if we run the Docker images command to see the list of images on the system, we should be able to see the centos image as well.

Removing Docker Images

The Docker images on the system can be removed via the docker rmi command. Let’s look at this command in more detail.

Few other widely used commands are:

docker images -q :to return only the Image ID’s of the images.

docker inspect :  to see the details of an image or container.

Docker – Containers

The basic purpose of Docker is to run containers, which are essentially instances of Docker images.

Running a Container

We use the run command to run a container. For instance

sudo docker run –it centos /bin/bash : to run the  instance of the CentOS system on the Ubuntu server. Then, press Crtl+P to return to the OS shell.

Listing of Containers

We can list all of the containers currently running on a machine using the docker ps command

sudo docker ps

Other commands are:

docker ps -a :used to list all of the containers on the system

docker history : to see all the commands that were run with an image via a container.

Docker – Working with Containers

docker top : to see the top-level processes within a container.

docker stop : to stop a running container.

docker rm : to delete a container.

docker stats : to provide the CPU and Memory utilization of a running container.

docker attach : used to attach to a running container, and after attaching to the Docker container, you see the process utilization in that container.

docker pause : to pause the processes in a current running container.

docker unpause : to reverse the pause, i.e., unpause the processes in a running container.

docker kill : to kill the processes in a running container.

This is just the tip of the iceberg of what you can do with Docker. But once you’ve installed and started to understand the commands, you can begin to explore the endless possibilities!

Creating a multiplication Skill in Alexa using python

Written By Jyotsna Rajaraman

Hi! I'm Jyotsna, an electronics and communication undergrad who likes reading, writing, talking and learning. So when it comes to teaching, all my favorite things come together! I hope my articles have helped and taught you something. 🙂

RELATED POSTS

Python Regular Expression

Python Regular Expression

Python is a general-purpose high-level programming language. Python is mainly used as a support language to software developers. It helps in building control and management and also in testing. The syntax python uses is very simple and similar to the English language....

Introduction to MicroPython and ESP8266

Introduction to MicroPython and ESP8266

For ages, C and C++ have ruled over the embedded system industry. Fast prototyping is an important aspect of the industry today. In fact MicroPython is the best suited for fast prototyping. Students and engineers are becoming very familiar with the Python programming...

Five Best Python Projects for Beginners

Five Best Python Projects for Beginners

Learning and practicing of any programming language can be monotonous. Also, only learning can not be the perfect gain of knowledge if we don't put it into some implementation. Likewise, Python programming language can be interesting but until we don't use it in some...

How to convert .py into .pyc? Compilation of Python Code

How to convert .py into .pyc? Compilation of Python Code

In this article we will see what is a pyc file ,how is it formed,how to convert and compile a pyc file. When we run a code in python it actually goes through a couple of steps before our program reaches the virtual machine It is compiled to bytecode.Then it is...

How to create and install a Python Package?

How to create and install a Python Package?

Requirements Check the tools pip --version pip install wheel What is Python Package Index? What is Distutils? Creating a Package Directory Structure some_root_dir/ |-- README |-- setup.py |-- an_example_pypi_project | |-- __init__.py | |-- useful_1.py | |--...

Object-Oriented Programming in Python

Object-Oriented Programming in Python

Python Classes and Methods Python is an object-oriented programming language. Classes provide a means of bundling data and functionality together. Creating a new class creates a new type of object, allowing new instances of that type to be made....

Python Flask Tutorial

Python Flask Tutorial

Flask is a web framework that provides libraries to build lightweight web applications in python. It is developed by Armin Ronacher who leads an international group of Python enthusiasts (POCCO). Contents What is Flask? Flask Environment Setup First Flask...

Python Numbers

Python Numbers

In this article you will learn about types of numbers in python and their mathematical operations. So these are the contents of this article : Introduction Decimal Need of DecimalFractionsMathematics Introduction Python supports integer, floating-point number and...

Python File Handling

Python File Handling

In this article, we will discuss all about file handling in Python. Let us have a quick look at the contents shown below: IntroductionFile openSyntaxRead filesParts of file to readRead linesloopChoose filesWrite filesAppendSplitting wordsCreate a new fileSeek...

Python Lambda

Python Lambda

In this article, we will discuss on Python lambda. Let us have a quick look on the following contents shown below: IntroductionAdd two numbers using LambdaSum of 10 natural numbersMultiplicationSmaller of two numbers Introduction Lambda functions are the anonymous...

Python Functions

Python Functions

In this article, we will tell about Python functions. We should also know about function defining function calling and variable arguments. Let's have a quick look on the below contents : IntroductionFunction CreationDefinitionDeclarationCallArgumentsRequired...

Python While loop

Python While loop

In this article, we are going to focus on while loops used in python with suitable examples. The content of this article is shown below: IntroductionThe break statementContinue in whileElse in while loop Introduction While loop in Python is a primitive type of...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....