T-Plaza, 6th Floor, Thika, Kenya
+254 703 412 771

Introduction to docker containers

Do Your Business, We Secure

Introduction to docker containers

Hello everyone, welcome to another blog series. This time round we’ll be covering docker containers. We are going to be looking at what docker is, the technology stack behind it in comparison to virtualization, the major differences between an image and a container as well as how to push and pull an image from the docker hub repository, among other things. We also have a video that explains the steps, you can check this out on our YouTube channel.

So without further ado adjust your sails and lets cruise this ship to the dock.

When the concept of virtualization was first introduced in the 90’s by IBM, this was huge news given  how big computers were back then. This meant that DOS programs could run on UNIX systems just as they would natively without requiring additional hardware and vice versa. This has evolved over the years and today we have a newer way of not only virtualizing the hardware but also the operating system. Which is what docker is.

. . .

What is Docker? I hear someone in the back row ask.

Docker is a platform as a service (PAAS) that enables users to run applications in an isolated environment known as containers. Docker achieves this by virtualizing the operating system as opposed to how virtual machines virtualize the hardware.

To help us better understand docker we are going to present a scenario. Imagine you are part of a team consisting of developers, marketers, testers among others. You are supposed to deploy an application on a client’s machine however the application has a lot of dependencies. The application can only run  with a specific version of the dependency otherwise there is going to be a configuration issue.

 Since there are many versions of dependencies one way of ensuring that we have the exact version is by deploying the application in a bundle that contains all its requirements. This way when the application is deployed somewhere else it runs just as expected.

Fig: difference between docker and hypervisor (an illustration)

. . .

What makes it up?

Docker as a service is made up of the following components that we’ll be looking at:-

(i) Docker image – the docker image consists of the configuration files, the dependencies and all the underlying software components required to run an application.

(ii) Docker container – the docker container is a running instance of an image. So after downloading(pulling) an image we would run it in a container.

(iii) The Docker registry – the docker registry is a repository for docker images. This can be public  or private in case of being public, the registry is accessible to all and in case of being private the registry is only accessible to allowed users.

. . .

Installing docker

As we had stated earlier docker is a service so to install it we’d have to pull it off the linux repository (in the case of linux systems). Until recently it was quite hard to install docker on  windows & mac but that has changed.

We need to run the following commands but first we’ll start with updating our Linux repository.

sudo apt get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

The last command will install the docker engine, docker containerd and docker compose.

The docker contained is the runtime (process)that creates, runs and destroys containers.

The docker compose plugin will create run and destroy multiple containers concurrently.

What a way to kill multiple birds with one stone eh?

. . .

Pulling an image from the public docker repository?*********

For us to starting working with docker, we will start by pulling an image from the public repository, the command for  that is

docker pull <image name> note in this command we are actually pulling an image from the public repository.

Fig: docker pull

If we were to pull(download) from a private repo we would have to input the name of the private repo at the end.

docker pull <private_repo/imagename> 

. . .

List all images locally

We could have a look at the images that we have in our local repo by running the following command:-

docker images – this should show all pulled images.

Fig: run a list of all docker images

Working with an image****************

After pulling an image we can make changes to it by running it inside a container. The command for that would be.

docker run <image_name> 
Fig: run docker non-interactively

However, we wouldn’t see anything on the screen as the command would be executed pretty fast and exit. Try it and see what it shows.

In order for us to see the command in the container in action we would run the following command

docker run it <container_name> sh
Fig: run docker container in interactive mode

In the above case <it> is telling docker to take us inside the container and the sh is instructing docker to drop us in the bash shell.

In the bash shell we can pretty much run any command as though we were running the container natively, we could run  the ls command to list all the files and directories.

Fig: running commands inside interactive container

. . .

Pushing an image to the docker repository

After pulling an image we could make changes to it, so for instance if we are working in a team environment, we could make changes to the image build it up and push it to docker repository. Or we could pull an image from the official docker hub and rename it as an unofficial release before pushing it. We are going to build an image from the alpine container we just ran.

To create an image from a docker container we would run the following command

docker commit <name or id of container>  <new name renamed to containing:tag_no>
Fig: committing an image from containers

After creating the image all we are required to do is push it to the github repo

docker push invisirack/myalpine:2  
push an image to docker repository

If we are to look at our docker repository we see we have the image pushed.

Docker image on repository

We hope this has been informative, remember to check out our other blogs . From as here, we say Adios and we hope to see you on our next blog.

Tags: , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *


Powered by WhatsApp Chat

× WhatsApp Us...