Docker Container Tutorial That Is Perfect for Noobs

docker containers tutorial, docker containers, docker

Docker Container Tutorial

In this docker container tutorial, we will take things simply and nicely. If you were looking for something that will give you enough understanding of docker containers, then welcome.

I will make one thing clear at the start of this docker container tutorial. I am in the stage of learning container technology myself. If you are feeling embarrassed or angry for calling you a noob, then here is something for you: I am a noob myself, a noob who is a little higher on the totem pole then a complete noob.

This docker container tutorial will be a test of my knowledge as I will try to explain the concept of the containers to you. If you are an expert in the field, then I welcome you to constructively criticize me and share your knowledge in the comments section. We will start by sharing some history; we will get to know why containers became a need.

The Bad And Uncertain Times

It is a known fact that every business needs a computer/web application to function progressively. We all know that most of the applications run on servers. This docker container tutorial that you are reading is on a server. In the old days, there was one server assigned to one application. No technology would allow you to run multiple applications on a single server, at that time. It was just challenging to do. There were security and safety issues.

Every time a new application was built, there was a need for a server. The businesses would buy servers that were powerful and fast. It was done to avoid any bottlenecks. If the server could not handle lots of transactions and traffic, then it would mean the business would lose customers and revenue. To avoid this scenario, more immense and powerful servers would be preferred. This solution was overkill because the application would not need big and powerful servers. It caused a massive waste of resources and money.

Sign of Hope, VMware Saves The Day!!!

As businesses were suffering from the dilemma of wasted resources, VMware introduced a new technology called virtual machines. A virtual machine allows you to create multiple OS instances on a single host OS. For example, if you have a Windows operating system and if you install a virtual machine. You can install other operating systems and use them as if you are using another computer. You can do anything in them, and it would not affect other operating systems or your primary Windows operating system. That is cool, right?

After the introduction of virtual machines, businesses did not need a new server whenever they made a new application. They could squeeze multiple applications in a single server, and everything worked fine. Many businesses were even able to utilize the spare powerful servers that they had lying around.

But there was a problem. As game-changing VMs were, they were not perfect. It turns out that every VM requires a dedicated OS is a big problem. Every operating system installed in a VM consumed CPU, RAM, and storage. When there are many VMs, every OS would need dedicated resources. Meaning that even if the application were lightweight, OS would take use up more resources.

Another problem was the licensing cost. Every time you would make an application, it required an Operating System; this means you would have to spend a lot of money. As you can probably guess, it was a massive waste of the company’s capital and resources.

Containers Get Introduced

The applications that would run in a server that was probably running on a VM were hard to deploy anywhere else. If the application has to run on another system or platform, it will create many technical issues. The old problem(The one that we discussed in the above section) was still going nowhere.

These problems were gone when the container technology was first introduced in Linux back in 2008.

Containers are roughly similar to the VMs, but there is one significant difference. They do not require a full Operating System. Every container shares the same OS. In this way, a considerable amount of CPU resources are freed up. Containers are isolated environments in which application functions without interfering with any other applications. Every container will have its virtual file system with necessary libraries, binaries, and any other resource that the application will need. This makes containers highly portable as they can smoothly function anywhere as long as they have the same operating system as before.

Although the containers were useful, they were very complex, and not many organizations could use them effectively.

Docker Makes an Entry

Docker introduced Docker container in 2013 and took the world by storm. Docker containers are industry-standard nowadays. If you put it, Docker corporation made containers simple and easy to use for everyone.

So yeah, to understand Docker, we have written this docker container tutorial. In the next sections of the docker container tutorial, we will be teaching you how to work with Docker, images, and all of the basic stuff.

Installation of Docker

This docker container tutorial assumes that you have a Windows operating system installed. If you have Linux or macOS installed, then do not worry. Most of the basic commands shown in this tutorial will not be OS-specific.

If you have Windows installed, there is a detailed guide on Docker’s website on how to install Docker on Windows. You can click this link to install Docker. If you Linux or macOS, then you can click this link or this link, respectively. In this docker container tutorial, we will be performing everything in a Windows OS environment.

You need to have an account on Docker hub too. If you have used Git and Github, then you will have some idea as to why we need an account. Making an account on the Docker hub will help you in making your repositories and manage your containers. There are other repository management services, but Docker hub is the official and supported by Docker Inc.

Once you have installed Docker, you can test if the installation was successful by typing this command.

docker containers tutorial, docker containers, docker

What is a Docker Image

The simplest way of defining a docker image is that it is a stopped container. When the image is run, it turns into a container. The image contains the application and a minimal OS file system. It is like a stopped virtual machine that is lightweight. If an image is public and available for use, people can download the image from the Docker hub and run it. That image will then be called a container.

It is a little weird, but that is how Docker decided to take things, so we will have to deal with it.

If you want to check what images you have downloaded into your system than you can enter

docker containers tutorial, docker containers, docker

If you have freshly installed Docker or following this docker container tutorial, then you will see results similar to the image above.

Docker Pull Command

For you to download images, you will have to enter the pull command along with the image name and the tag. If you are downloading from an unofficial repository or a user account, then you will have to add the user name too.

When you download an image, it will get a unique ID. If you rerun the docker image ls command, you will see the image name along with other information.

In our docker container tutorial, we will be pulling a Microsoft’s PowerShell image.

docker containers tutorial, docker containers, docker

For some reason, Microsoft is considered as an unofficial or a user account. Remember, I said that if an account is not official, you will have to add the username too. In the above command, we are telling Docker to download an image that belongs to the user called “microsoft”, the image name is “powershell,” and the tag is called “nanoserver.” Tags are used to keep track of versions, but you can use them according to your purpose.

Running an Image

We have downloaded an image. To run this image on our system and turn it into a container is a straight forward task. Type the command that we have shown in our docker container tutorial.

docker containers tutorial, docker containers, docker

Think about it, you have downloaded a PowerShell image. When you run a container, it will run and then end. It is like starting a command prompt and closing it. There are images that have web applications that will run as long as you do not stop the container. But, in the case of this container, we will have to supply commands or open in an interactive mode. To open a container in an interactive mode, you will have to do something like this.

docker containers tutorial, docker containers, docker

We give -it flag, and we provide the name of the command-line interface that we want to interact with the container. You will see a change in the interface because the container will be open. If you opened the container in bash, then type ls, and you will see file structure as similar to Linux. You are literally inside your container with all its glory. In our docker container tutorial, we opened the container on Powershell.

Exiting Out of The Container

To exit out of the running container without stopping it. You will have to press Ctrl+P+Q. You will be out of the running container without stopping it. If you want to stop the container when you exit out of the interactive mode then you will have to type the exit command that you would type to close the command line. For example, for bash, you simply have to press Ctril+C, and Docker will stop the container, and you will be back in the Docker Client.

Checking Running Containers

To check the containers that are in running status, you will have to type this simple command.

docker containers tutorial, docker containers, docker

If you are following this docker container tutorial, then you will see one container and its information.

Stopping The Running Container

Until now, in our docker container tutorial, we have downloaded and ran a container. To stop a container that is already running, we will have to type this command.

docker containers tutorial, docker containers, docker

When you run a container, your Docker Engine gives it a random name that is short and concise. In our docker container tutorial, we are just using the official image name, but you can use the container ID or container name to reference the containers.

Deleting The Container

A time comes when you will have to delete a container when you don’t need it. Running a container from an image is so easy that people usually delete the container that they started. The image remains on the system, so it is not a hassle to rerun it again.

If you want to specifically delete a container, then you can do it in this way.

docker containers tutorial, docker containers, docker

Every container has a specific ID. You will have a different Id than in this docker container tutorial.

The practice of deleting all the stopped containers is so common that Docker now gives a command to perform that job.

docker containers tutorial, docker containers, docker

Conclusion

In this docker container tutorial, you have learned a little bit about the history and the basics of Docker containers. Congratulations!! you are not a big noob. You know some basic stuff, and it will help you in understanding the advanced knowledge that you will gain while on the docker learning journey. I will provide you with a link to an article that will teach you some of the advanced stuff. If you want to learn more, I am guaranteeing that you will find that article useful.

If you liked this docker container tutorial, then you can also check out our other articles.

Leave a Reply

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