DEV Community

manish srivastava
manish srivastava

Posted on • Updated on

This is 7 MINUTES CHALLENGE between you and me. I have to tell you docker, lxc, networking, cloud, extend you can do it DIY.

IMP REQUEST:
You are most welcome to join my team form for joining .
Also you are most welcome to join OPEN SOURCE INTELLIGENT SYSTEM (OSINT)if you can help in open source project regarding safeguarding humans from various diseases like CORONA outbreak
https://github.com/Manishfoodtechs/OSINTHRH/wiki

This is 7 minutes challenge between you and me. I have to tell you about docker, lxc, networking, cloud, etc to extend that you can do it DIY. And you have to concentrate for 5 Minutes. Let us assume, we all are 5 years old and we are going to learn something about post-graduation. I will keep this complex subject to a possible simplified form.

LEVEL ZERO: Difference between Desktop & Server

what is a desktop? A desktop contains a CPU, RAM, Hard Drives, etc and Operating system. This operating system can be Windows, Linux, Mac, etc. You have a graphical interface (GUI)in a desktop but if you remove GUI it becomes the server. we call it " bare-metal server".

LEVEL ONE: Getting many servers inside one server

Virtualization

Metal servers are most costly. So, people shared them and call them Virtual private servers (VPS/VM). But everyone doesn't want the same OS like windows. Some want Linux. 20 years back, comes a piece of software called " Hypervisors" made possible to run Windows and Linux from the same machine, and this technology is called virtualization. 60 years back IBM started work on virtualization.
Time line, optional read here.

LEVEL ONE: FIGHT BETWEEN HYPERVISORS- a piece of software that creates an operating system within operating system.

There are three types of Virtualization full virtualization( hardware virtualization), para-virtualization, and OS-level virtualization.

Full virtualization: Kernel-Based hypervisors (KVM etc..) fix the RAM/cores/ hard drive etc for each machine. This created a resource problem among VMs as little-used machines have good resources and heavily loaded machines with little resources.

FIGHT BETWEEN MACHINES- SOLVED BY RESOURCE POOLING
Instead of virtualization at the kernel, these new OS based hypervisors ( OpenVZ, etc..) created a pool of resources like ram, HDD, etc and share them with virtual machines when they require. This somewhat controlled the fight.

VIRTUAL MACHINES ARE TRUNKY, NEED LIGHT SOLUTION
Kernel Hypervisor or OS-based Hypervisors based machines required large files [.iso (1-4 GB)] to get installed. This takes time to provision a small Virtual machine. Also, they are heavy on Hard drive. To counter this, a new lightweight technology spined in recent years we call it "containers". They are somewhat similar to OS-based visualizers except they have compressed images on the internet which you can download and create OS of your choice.

WHEN WE HAVE GOOD LANDS TO WALK, WHY WE THEN NEED CLOUDS
Today you can get the most popular OS - Ubuntu from iso cd (1 GB+) and also in a container (93 MB). This huge difference in size and time to get ubuntu between cd and container is the real need of cloud.

Must Read: Please refer to my previous posts regarding creating your cloud service like the digital ocean or google cloud. Part 1 and Part-2 and Part-3
Level one sum up: 20 years back we able to get many operating systems from one operating system but resource was a problem. Full hardware virtualization then paravirtualization then containers.LXD and dockers are well-known containers. READ MORE: https://www.unixarena.com/2017/12/para-virtualization-full-virtualization-hardware-assisted-virtualization.html/

LEVEL TWO: Want to create your own Virtual Machine?

you can buy a metal server with KVM or in your windows desktop use VirtualBox or VMware play station. You will use a .iso image (approx 1GB) to spin your Linux servers on windows desktop.

LEVEL THREE: Containers?

Instead of using the .iso image (approx 1GB), we will use small images (100 MB) hosted on the internet to spin our virtual machines (a better word is a container).

The two most popular container technologies are LXD and Dockers. But they are a bit different. In LXD you launch an image of server like VM but in docker, you can launch an image of the server( minimal to lxd) and images of apps.
Okay let me give you an example:

Suppose you have PHP website. To run this PHP website you need an apache server (like xampp) and MySQL database.

In LXD you will create a ubuntu server and inside it, you will install the apache server and MySQL database. [1 container holds inside apache, mysql]

But in the docker, you can have two different containers: one for apache and one for MySQL. And why just one container for the apache server? let's take two apache containers and three MySQL ... if one fails others will start running ... and our app will never "Get OFF the Internet".[ different containers hold different apps]

LEVEL FOUR: How to use Containers?

Containers are servers!!! let's assume like this.
So, we should know:
(1) How to Launch a server.
(2) How to start a server.
(3) How to do coding inside server:-put apps/ programs inside the server.
(4) how to stop a server.
(5) How to make our server accessible to the world via internet.
(6) How to create an Image of the server to create a new server from it.
(7) How to manage many servers by a single program within a single host.
(8) I have servers hosted in a different parts of the world. can I manage it by a single program?

LEVEL FIVE: Answers...How to use Containers?

Install lxd: snap install lxd
Install docker: sudo apt install docker.io -y && sudo systemctl enable --now docker && sudo usermod -aG docker root && docker --version

Before we start: Remember: Ubuntu is 'image' and we create 'container( say server)' from this image. The host is the machine we using to create as many as containers on it of our choice like ubuntu, centos, fedora etc.

Below SERVER = CONTAINER (say)

(1) How to Launch a server.
LXD: lxc launch ubuntu:18.04 myfirstcontainer
Docker: docker pull ubuntu:latest and docker run -it myfirstcontainer ubuntu:latest

(2) How to start a server.
LXD: lxc start myfirstcontainer
Docker: docker start myfirstcontainer

(3) How to do coding inside server:-put apps/ programs inside the server.
let's get inside the container and do some coding like installing Nginx server.
LXD: lxc exec my first container bash
Docker: docker ps -a --> get container id and then do docker exec -it ed58974dd bash

ed58974dd is the container id given by docker. Unlike LXD, you have to use docker provider random ids'

After installing ... type exit to come out of the container.

(4) How to stop a server.
LXD: lxc stop myfirstcontainer
Docker: docker stop ed58974dd

(5) How to make our server accessible to world by internet
LXD: whenever you create a container, you get an IP address of that container. ip a will give you the address of container or do lxc list. We had created an lxd container with nginx. ngnix will listen on port 80.
internalip:80. But this internaip cant be accessed by internet.Only host IP is available on internet. To route this internalip:80 to hostip:8945 ( whatever port you want) you need to do iptables.

https://dev.to/manishfoodtechs/networking-is-easy-connecting-multiple-vms-servers-containers-devices-on-single-external-ip-in-one-command-139a here is an article to help you :)

Docker: In docker, after the creation of containers it's bit difficult. So you should know prior to spinning docker image which port you will require. for this example of nginx we know its port 80 so, our syntax can be docker run -p 8945:80 -t -i Ubuntu. Also, There are ways to use iptables in docker

(6) How to create an Image of the server to create a new server from it?
Now we have created a container to hold a Nginx inside it. We may require to use it later date for spinning a new container with this image.

LXD: lxc stop myfirstcontainer

lxc publish myfirstcontainer --alias ubuntunginx
lxc image list
lxc image export ubuntunginx
lxc image import ubuntunginx.tar.gz --ubuntunginx
lxc launch ubuntunginx mysecondcontainer

The exported image is as tar.gz in root/ folder just do ls. You can then export this tar.gz file to your drive or email : or whatever you want

Docker: docker commit -m "ubuntu1804" -a "root" ed58974dd manishfoodtechs/ubuntunginx:latest

As Tar ball: docker export ed5 > ubuntunginx.tar.xz

Push to docker hub: In docker, you can push your images to docker hub.
docker push manishfoodtechs/ubuntunginx:latest
docker list images

(7) How to manage many servers by a single program within a single host?
LXD: LXD is for BIG BOYS. It gives you the freedom and unlimited way of your way. There are few lxd containers management programs that you can install and manage lxd containers: https://lxc-webpanel.github.io/

Docker: https://www.portainer.io/

(8) I have servers hosted in different parts of the world. can I manage it by a single program?
Kubernetes and docker-swarm

I will request you to download VMware workstation on your laptops/ desktops. Try to spin the ubuntu 18.04 LTS server as host. Then inside host you can run lxd and docker. Also, try to run docker inside LXC . But you can't run lxc inside docker but docker inside docker.

I hope you people like the above article and learned something.

You are most welcome to join my team form for joining .

Contact email: Manishfoodtechs@gmail.com.

If you have any problem, our team is also engaged in professional consultancy and delivery.

Top comments (0)