Tuesday, August 31, 2021

Day1 - Docker - Introduction to docker

 Docker is very light weight mini os which does not include kernel. It is good for developers and sysadmins to build, ship and run the distributed application. 
Containerization::
- It is not a new concept. There were jail, zomes, containers, LDOMs,, LXC - linux containers
but all of these virtualization technologies could not do optimim job. 
Docker took over. Its a client/server model. First release in 2013.
Advantage of docker::
- Reduce the size of dev env with the help of small os foot print
  Centos/ubuntu
VM os size     4 GB
Container size  200MB(appx)
- Docker does not need kernel, it gets all support from host os.
- You can develop on one platform and deploy on any platform
- Container/dockers are very light weight
Docker os is called docker images
- very lighweight os and easy to deploy

Lets contair the VMs
Guest VM | Guest VM        c1|c2|c3|c4  -> Containers - container contains some binary/library
Virtualization layer Host OS + Docker Service
Host OS HW
Hardware

You can develop your app -> create your image -> upload to repo -> install (pull) and start using it
- Install on windows/linux/Mac. It just works on any env.
- You generate project image (tomcat, ubuntu, centos)
 For docker imatallation, you can follow the link below
https://get.docker.com/
To install on windows, docker for windows
You can use cloud env link gcp/aws
just follow the installation steps
$ sudo usermod -aG docker jay
$ sudo systemctl start docker
$ sudo systemctl enable docker
$ docker version

Docker works on concepts of image.
Docker registry -> Where docker images are stored/present
hub.docker.com -> docker HUB
You can have public/private registry (repo)
- company info may go private.
search -> centos and look for official
search for apache, java, ubuntu, nginx
these are pre-configured images.
To download the image
$ docker pull centos
check available images
$ docker info -> shows everything . Check the output line by line.
image - pre-configure class (group of objects)
container - is like os and it has application.
How to run container
1. Interactive (it) mode 
2. Detach (dt) mode
Running container in interactive mode
$ docker ps
$ docker run -it centos bash
it -> interactive
centos - name of image
bash - shell it will load
when you run the command, you will be on centos bash prompt.
# cat /etc/os-release
Now, lets try something interesting
$ linux1
$ docker images  -> lists images
look at the output carefully
- check the size, its so light
every image has container ID.
$ exit
you docker stops. 
$ docker ps -> you will see no container running
This is an interactive mode where container dies when you exit out.

Lets run an docker instance
$ docker run -it centos bash
open a new instance of host os and run
$ docker ps -> you will see continer still running
run the top command on both host and container.
you will see lots of processes on host but very few on container.
now, exit out from container, and run
$ docker ps ->  no container is running
$ docker ps -a -> you will see the history
2. Running docker in detach mode
$ docker run -dt centos bash
-dt -> detach mode
you will still on host command prompt, docker is running on the background
$ docker ps -> you will see the instance running
How to loign to docker
$ docker exec -it bash
look at the error message
$ docker exec -it <container id> bash
you will get container id from docker ps command output
you exit out of docker. it is still running. 
if you want to stop, you have to stop manually
$ docker ps
$ docker --help -> search for how to stop
$ docker container stop <container ID>
The beauty of docker is that you can ship your application fast and 
docker starts in seconds.
docker is infact a process. 
HW: download image/install some container such as apache/tomcat/nginx/java/jinkins or more ..

No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...