Containers and Virtual Machines

Vinci Sharma
3 min readOct 24, 2020

--

Photo by Martin Adams on Unsplash

When I first started reading about Containers, I was surprised at the various comparisons between Containers and Virtual Machines. In my opinion not only do these comparisons complicate a simplistic concept, they are completely unnecessary and make no sense what so ever. So what are Containers and how can they be explained to someone who is just starting out, lets have a look.

To really drive home the point on what containers are, the comparison back to virtual machines needs to stop. To demonstrate what containers are and how they are run, lets start some containers.

Step 1 Run a container

Let us run one of the most common containers nginx

docker container run --publish 89:80 --detach --name web nginx

The above command runs a nginx container and names it web. It also opens port 89 from the host to port 80 in the container. The detach option ensures logs are not displayed on the screen. The container is based off the nginx image which is pulled from Docker registry if not available locally.

Running a nginx container on Ubuntu

That was easy, now lets see if the container is actually running !

docker container ls
The running nginx container

The nginx default page is also reachable from a browser on the host.

Reaching the nginx default page from the host browser

Step 2 Check the processes running inside the container

docker container top web
Processes running inside the nginx container

The container top command displays the processes running inside the container.

Step 3 Check the processes running on the host

So far we have been able to see the processes running inside the container. Let us see if we can find this in the processes running on the host.

ps aux | grep nginx
Processes running on the host

On running the “process status” command directly on the host and performing a grep for nginx, the same two processes running inside the nginx container are visible. Thus containers are nothing but a process running on your host. The container interacts directly with host kernel.

On stopping the container, the nginx processes running on the host also disappear.

Stop the container and check for running processes

Thinking of containers running as processes on the host from an image which contains all application binaries, libraries and other dependencies really helps simplify the whole concept.The comparison with virtual machines is not required.

--

--

No responses yet