Getting Started with Docker
Working with Containers:
What is a Container?
So, you know how a virtual machine manager or a hypervisor, how it grabs physical resources like CPU, RAM, storage, networks, then, it slices them into virtual versions, so virtual CPU, virtual RAM, virtual NICs, all that goodness, and then it builds virtual machines out of them, virtual machines that look, smell, and feel like normal physical servers. Well not so with containers. Now, keeping this somewhat high-level here, instead of slicing and dicing physical server resources, Docker and other container engines slice and dice operating system resources. So, they slice up the process namespace, the network stack, the storage stack, the file system hierarchy actually. In effect, every container gets its own PID1, process ID 1, every container gets its own root file system, that's obviously / on Linux and c on Windows. So, hypervisor virtualization virtualizes physical server resources and builds virtual machines. Container engines like Docker, they're more like operating system virtualization, they create virtual operating systems, assign one to each container, inside of which we run applications. And they're way more lightweight than VMs. Okay, that took me, oh, check
Docker "run" command
--docker version
#ro run a container
--docker run hello-world
#list running containers
--docker ps
--docker ps -a
--docker info
#to see info about images
--docker images
#ro remove images
--docker rmi IMAGENAME or IMAGE ID
#to start containers
--docker start <container>
#to stop containers
--docker stop <container>
#to remove containers
--docker rm <container>
docker run -d --name web -p 80:8080 nigelpoulton/pluralsight-docker-ci
-d : telling the daemon to start the container in detached mode, basically throw it in the background and dont latch it on to my terminal here
-p 80:8080 :
nigelpoulton/pluralsight-docker-ci : we tell which image to use
docker run -it --name temp ubuntu:latest /bin/bash
-it : Actually want to interact with this one, so i am saying open it standard in stream and assign it a terminal
Ctrl P+Q :
//to stop all the containers
docker stop $(ps -aq) : where "-a" says gives us all containers and "q" returns containers ids
//to remove all containers
docker rm $(ps -aq)
//to remove all images
docker rmi $(docker images -q)
Swarm Mode and Microservices:
Swarm mode theory
A collection of Docker engine joined into a cluster is called a Swarm.
And then the Docker engines running on each node in the swarm are said to running in swarm mode.
More manager if we have, the harder it is to get consensus, or the longer it takes to get consensus.
i.e 2 or 3 people deciding which restuarant to go to is way easier than 20 people deciding.
Configuring Swarm Mode:
sudo docker swarm init --advertise-addr 127.0.0.1:2377 --listen-addr:127.0.0.1:2377
sudo docker node ls
To know the commands for joining manager or worker
sudo docker swarm join-token manager
sudo docker swarm join-token worker
You can promote worker node into manager node
sudo docker node promote <ID>
Services :
Services one of the major construct introduced in 1.12.
They are all about simplifying, robustifying large-scale production deployments.
sudo docker service create ..
sudo docker service update..
sudo docker service scale..
sudo docker stack deploy
sudo docker service create ..
sudo docker service update..
sudo docker service scale..
sudo docker stack deploy








Comments
Post a Comment