Install Thoughts#
Docker switched from using Virtual Box to HyperKit. (very cool!!!) https://github.com/moby/hyperkit
Moby Linux - Based on Alpine Linux https://alpinelinux.org
IANA ports used for docker Engine: 2375 Secure Engine POrt: 2376 Swarm port: 2377 (but it could be any port)
docker version
docker info
docker run hello-world (starts a new container) docker pull - copies images to the Docker Host
docker ps - list containers that are running docker ps -a - list containers that were running
docker images - list local images
docker rmi name:tag - to remove an image
docker start container docker stop container docker rm container -f if you want to force stop and removal
docker run -d start in detach mode, in the background –name web (give it a name/unique) -p 80:8080 map port 80 on the docker host to port 8080 in the container which image to use, you can have top levels or secondary ones with namespace/image
docker run -it , interact with this container and start a terminal –name temp ubuntu:latest /bin/bash
You are now in the terminal using a bash shell. Containers are usually single process constructs. ps -elf will only show bash running top will show the same If you type exit, it will shut down the container. Ctrl P+Q will exit you from the container but keep it running.
docker stop $(docker ps -aq) -a list all containers -q give the command quietly
docker rmi $(docker images -q)
Docker 1.12 introduced the following!!!
A native cluster (multiple docker engines) is called a swarm Engines that are running in a swarm is called swarm mode Manager nodes maintain the swarm (managers are also workers) H/A recommend 3 or 5 Only one is leader
The Raft Consensus Algorithm - distributed consensus The more managers you have, the harder it is to get a consensus
Worker nodes just takes tasks from managers.
If you are not in swarm mode, you can’t run services
Services is a declarative and scalable docker service create –name web-test –replicas 5 it will being to spin up 5 containers/tasks going to spread them across all the worker nodes in the cluster the managers is always going to make sure 5 of them are running, if one should die, it will start up a new one actual state should always match desired state, this is checked by the reconciliation running in the background
Tasks - is an atomic unit of work that is assigned to a worker node We tell the manager about services, then the manager assigns the work of that service out to worker nodes as tasks tasks have additional metadata about how to initiate the container and runtime info tasks mean “containers”
We are going to create 3 managers and 3 workers main call out is that everyone of these need to talk with each other in the end we should have a 6 node swarm
docker swarm init –advertise-addr ipaddess:port –listen-addr ipaddress:port –advertise-addr - This will tell docker no matter how many nics I may have this is the one to use for swarming. Not required, but its a best practice –listen-adr - Which IP to listen for requests Needs to be the ips of the host you are on
docker swarm join-token manager - This will output the info to add another manager docker swarm join-token worker - This will output the info to add another worker
docker info will show you how how many managers/nodes you have
docker node ls - can only be ran from a manager the asterisk will show which node you are currently on if there is no manager status, then you know its a worker node
docker node promote id This will promote a work to a manager
Any manager can proxy commands to the leader, and if the leader should go away, a new election is done for a new manager.
docker network create -d overlay tux-net
docker network ls
Now that we have the swarm setup, let’s setup a service docker service create –name myWebSite –network tuxnet -p 8080:8080 –replicas 5 nginix
docker service ls this will show all 5 services up and running
docker service ps myWebSite
docker service inspect myWebSite This will show you the config of your service
overlay networks???
native container aware load balancing is called the routing mesh This can augment existing non-container-aware load balancers
docker service scale myWebsite=7 or docker service update –replicas 7 myWebSite This will scale up the services which should show 7/7
As of 1.12 adding new nodes or bringing back online nodes, does not rebalance existing tasks
docker service rm myWebSite
docker node ps self
docker service inspect –pretty myWebSite
docker service create –update-parallelism 2 - will update 2 tasks at a time –update-delay 10m - will wait 10 minutes and then run the next set
docker service update –image myWebSite:v2 –update-parallelism 2 –update-delay 10s myWebSite
docker service ps myWebsite | grep :v2 |
docker stack - application comprising multiple services -deployed from distributed application bundles (DAB)
docker-compose build
docker tag localimagename tuxlabs/imagename
docker login
docker push tuxlabs/imagename
Need to update my docker compose files to remove the build lines and replace them with image lines. Also going to remove the volumes as they are part of the image now.
docker-compose bundle - this will create you a .dab file
docker stack deploy myWebSite
Can’t set the number of tasks that need to be running in the early iteration. Need to double check on this.
docker stack tasks myWebSite
docker stack rm myWebSite