Every developer has struggled with wrestling infrastructure. The application that runs so well locally simply fails in UAT or worse, in the production environment. More so when it’s a cross-platform solution. I used to work on a Windows machine and had to deploy my java web app to Solaris. Even though Java is a cross-platform solution, there are slight differences here and there when it’s running on a different platform. It’s always a challenge to perform regression test on Solaris to make sure everything works exactly as I intended.
Introduction
Docker solves this problem. Docker Engine enables containerized applications to run anywhere consistently on any infrastructure, solving “dependency hell” for developers and operations teams, and eliminating the “it works on my laptop!” problem.
Container vs Virtual Machine
Containers and virtual machines have similar resource isolation and allocation benefits, but function differently because containers virtualize the operating system instead of hardware. Containers are more portable and efficient.
Container
Container is an abstraction at the application layer that packages code and dependencies together. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space. Containers take up less space than VM, can handle more applications, and require fewer VM and OS.
Virtual Machine
VM is an abstraction of physical hardware turning one server into many. The hypervisor allows multiple VMs to run on a single machine. Each VM includes a full copy of an operating system, the application, necessary binaries and libraries. Taking up tens of GB, slow to boot, and expensive to run.
Container and Virtual Machine
Container and Virtual Machine are not exclusive. In fact, they work well together to create great flexibility in deploying and managing applications.
Why is it so popular?
Docker sparks the movement of containerization – writing applications that run in the Docker engine. The reason? Dockerized applications are easier to test, and deploy. It’s generally worth it to spend a little more time upfront setting up docker and containerize application and reap the rewards down the road during testing and deployment.
Another reason to write a container-friendly application is that it is very easy to scale applications in a container. Since the application is platform-agnostic, and all dependencies are bundled into the docker image, it is easy to spin up another instance of the variable in the same or different machine. If this sounds like a good microservice solution to you, it’s because it is! Docker works very well with microservice and many have adopted docker for building microservices.
All you need to scale is to place a load balancer in front of the application and the application can now achieve high availability and is more resilient.
Kubernetes is an open-source container orchestration system for automating application deployment, scaling, and management. It manages Docker containers. It can automatically spin up a new instance of your application in docker, and configure load balancer to include the new instance.
How to install docker in Windows
Note
If you have installed Bluestack or similar virtualisation tool before, you might have disabled Hyper-V auto start. Enable it back with PowerShell:bcdedit /set hypervisorlaunchtype auto
- Search for “Turn Windows Features on or off” in Start and open the first setting that pops out
- Tick Windows Subsystem for Linux and Hyper-V
- Restart Windows
- Open PowerShell and run the following command
wsl --set-default-version 2
- Open Microsoft Store and install Ubuntu
- Launch Ubuntu, on the first launch, you will be prompted to enter username and password
- Download and install Docker Desktop for Windows
- Optionally, download and install docker-compose.
- Docker-compose is a convenient way to store docker run configuration in a file and manage container lifecycle easily
Run your first container application
- Open WSL console
- Run
$ docker run hello-world
- You will see a message from docker if you installed everything correctly
What’s next?
Congrats on running your first docker application!
Next, you might want to explore some open source project out there runs in docker.
- Pihole (https://hub.docker.com/r/pihole/pihole)
Open source network-wide Ad Blocking - Monica – https://github.com/monicahq/monica
Monica is a great open-source personal relationship management system