Skip to content

Commit f1b5cce

Browse files
committed
updated docker internals
1 parent 16553d5 commit f1b5cce

11 files changed

+424
-97
lines changed

docker/daemon/.namespaces.txt.swp

-12 KB
Binary file not shown.

docker/daemon/configure-storage-driver.txt

Lines changed: 0 additions & 32 deletions
This file was deleted.

docker/daemon/storage.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Docker storage drivers:
2+
3+
Storage is essential to almost any system, and containers are no exception.
4+
5+
Storage drivers are sometimes also called as graph drivers. the proper storage driver to use often depends on your operating system and other local configuration factors.
6+
7+
overlay2: current Ubuntu and CentOS/RHEL veresions.
8+
aufs: Ubuntu 14.04 and older
9+
devicemapper: CentOS 7 and earlier
10+
11+
Storage models:
12+
13+
Persistent data can be manageed using several storage models.
14+
Filesystem Storage:
15+
1) Data is stored in the form of a file system.
16+
2) used by overlay2 and aufs
17+
3) Efficient use of memeory
18+
4) iefficient with write-heavy workloads
19+
Block storage:
20+
1) stores data in blocks
21+
2) used by devicemapper
22+
3) Efficient with write-heavy workloads
23+
Object storage:
24+
1) stores data in an external object-based stored
25+
2) Application must be designed to use object-based storage.
26+
3) Flexible & scalable
27+
28+
Device Mapper Storage Driver:
29+
Device Mapper is one of the Docker storage drivers available for some Linux distributions. it is the default storage driver for CentOS7 and earlier
30+
31+
we can customize Device Mapper configuration using the daemon config file.
32+
33+
Device Mapper supports two modes:
34+
loop-lvm mode:
35+
1) Loopback machanism simulates an additional physical disk using files on the local disk.
36+
2) Minimal setup, does not require an additional storage device.
37+
3) Bad performance, suggested use only for testing.
38+
direct-lvm mode:
39+
1) Stores data on a seperate device
40+
2) Requires and additional storage device.
41+
3) Good Performance, suggested to use for Production.
42+
===================================================================================================
43+
Configure a Storage Driver:
44+
45+
Get the current storage driver
46+
docker info
47+
48+
Two ways we can set the storage drivers
49+
1) Set the storage driver explicitly by providing a flag to the Docker daemon:
50+
sudo vi /usr/lib/systemd/system/docker.service
51+
Edit the ExecStart line, adding the --storage-driver devicemapper flag:
52+
ExecStart=/usr/bin/dockerd --storage-driver devicemapper ...
53+
54+
After any edits to the unit file, reload Systemd and restart Docker:
55+
56+
sudo systemctl daemon-reload
57+
sudo systemctl restart docker
58+
59+
2) We can also set the storage driver explicitly using the daemon configuration file.
60+
This is the method that Docker recommends.
61+
Note that we cannot do this and pass the --storage-driver flag to the daemon at the same time
62+
63+
sudo vi /etc/docker/daemon.json
64+
Set the storage driver in the daemon configuration file:
65+
{
66+
"storage-driver": "devicemapper"
67+
}
68+
Restart Docker after editing the file.
69+
It is also a good idea to make sure Docker is running properly after changing the configuration file:
70+
71+
sudo systemctl restart docker
72+
sudo systemctl status docker
73+
74+
more Info: https://docs.docker.com/storage/storagedriver/select-storage-driver/

docker/networks/docker-networks.txt

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
Networking in Docker:
2+
=====================
3+
Containers present unique challenges when it comes to networking. Docker includes multiple built-in solutions to these networking challenges.
4+
Docker implements container networking using a framework called the Container Networking Model (CNM) and manages the networking for containers.
5+
6+
The CNM utilizes the following concepts:
7+
8+
Sandbox: An isolated unit containing all networking components associated with a single container. Usually a Linux network namespace.
9+
10+
Endpoint: Connects a sandbox to a network. Each sandbox/container can have any number of endpoints, but has exactly one endpoint for each network it is connected to.
11+
12+
Network: A collection of endpoints connected to one another.
13+
14+
Network Driver: Handles the actual implementation of the CNM concepts.
15+
16+
IPAM Driver: IPAM means IP Address management. Automatically allocates subnets and IP Addresses for networks and endpoints.
17+
18+
Network Drivers:
19+
================
20+
Docker includes several built-in network drivers, know as Native Network Drivers.
21+
These network drivers implement the concepts described in the CNM.
22+
23+
The Native Network Drivers are:
24+
1) host
25+
2) bridge
26+
3) overlay
27+
4) macvlan
28+
5) none
29+
30+
with docker run we can use --net flag to attach network driver to container(s).
31+
32+
The Host Network Driver:
33+
------------------------
34+
The Host Network Driver allows containers to use the host's network stack direclty.
35+
1) Containers use the host's networking resources direclty
36+
2) No sandboxes, all containers on the host using the hsot driver share the same network namespace
37+
3) no two containers can use the same port(s)
38+
UseCases: Simple and easy setup, one or only few containers on a single host.
39+
40+
The Bridge Network Driver:
41+
--------------------------
42+
The Bridge Network Driver uses Linux bridge networks to provice connectivity between containers on the same host.
43+
1) This is the default driver for containers running on a single host (i.e, not in a swarm)
44+
2) Creates a Linux Bridge for each Docker Network
45+
3) Creates a default Linux bridge network called docker0. Containers automatically connect to this if no other network is specified
46+
UseCases: isolated networking among containers ona single host.
47+
48+
The Overlay Network Driver:
49+
---------------------------
50+
The Overlay Network Driver provides connectivity between containers across multiple Docker hosts, i.e. with Docker swarm.
51+
1) Uses a VXLAN data plane, which allows the underlying network infrastructure (underlay) to route data between hosts in a way that is transparent to the containers themselves.
52+
2) Automatically configures network interfaces, bridges, etx. on each hosts as needed.
53+
UseCases: Networking between containers in a swarm
54+
55+
The macvlan Network Driver:
56+
---------------------------
57+
The macvlan Network Driver offers a more lightweight implementation by connecting container interfaces directly to host interfaces.
58+
1) Uses direct association with Linux interfaces instead of a bridge interface.
59+
2) Harder to configure and greater dependency between macvlan and the external network.
60+
3) More lightweight and less latency.
61+
UseCases: When there is a need for extremely low latency, or a need for containers with IP addresses in teh external subnet.
62+
63+
The None Network Driver:
64+
------------------------
65+
The None Network Driver does not provide any networking implementation.
66+
1) Container is completely isolated from other containers and the host.
67+
2) if you want networking with the None driver, you must set everything up manually.
68+
3) None does create a separate networking namespace for each container, but no interfaces or endpoints.
69+
UseCases: When there is no need for container networking or you want to set all of the networking up yourself.
70+
71+
Managing Networks:
72+
==================
73+
We can create and manager our own networks with the "docker network" commands. if we do not specify a network driver, bridge will be used by default.
74+
75+
docker newtork ls
76+
docker network create NETWORK ( create a bridge network by default )
77+
docker network create --driver bridge NETWORK
78+
docker network create --driver overlay NETWORK
79+
docker network inspect NETWORK
80+
docker network rm NETWORK
81+
82+
docker network connect NETWORK CONTAINER
83+
docker network disconnect NETWORK CONTAINER
84+
85+
Embedded DNS:
86+
=============
87+
Docker networks implements an embedded DNS server, allowing containers and services to locate and communicate with one another.
88+
Containers can communicate with other containers and services using the serice or container name, or network alias.
89+
90+
docker run --network-alias ALIAS
91+
docker network connect --alias ALIAS
92+
93+
Example:
94+
Create a container with a network alias and communicate with it from another container using both the name and the alias.
95+
docker network create my-net
96+
docker run -d --name my-net-nginx --network my-net --network-alias my-nginx-alias nginx
97+
docker exec my-net-busybox curl my-net-nginx2:80
98+
docker exec my-net-busybox curl my-nginx-alias:80
99+
100+
Create a container and provide a network alias with the docker network connect command.
101+
docker run -d --name my-net-nginx2 nginx
102+
docker network connect --alias another-alias my-net my-net-nginx3
103+
docker exec my-net-busybox curl another-alias:80
104+
105+
Publishing Ports for Services:
106+
==============================
107+
Host vs. Ingress
108+
Docker Swarm supports two modes for publishing ports for services.
109+
110+
Ingress:
111+
1) The default, used if no mode is specified.
112+
2) Uses a routing mesh. The published port listens on every node in the cluster, and trasparently directs incoming traffic to any task that is part of the service, on any node.
113+
114+
publish a service port host mode:
115+
docker service create -p 8081:80 --name nginx_ingress_pub nginx
116+
117+
Host:
118+
1) Publishes the port directly on the host where a task is running.
119+
2) cannot have multiple replicas on the same node if you use a static port.
120+
3) Traffic to the published port on the node goes directly to the task running on that specific node.
121+
122+
publish a service port host mode:
123+
docker service create -p mode=host,published=8082,target=80 --name nginx_host_pub nginx
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Network Troubleshooting:
2+
There are several ways we can gather information to troubleshoot networking issues.
3+
docker logs CONTAINER ==> Get container logs
4+
docker service logs SERVICE ==> Get collated logs from the tasks of a service
5+
journalctl -u docker ==> Get Docker Daemon logs.
6+
7+
another way to troubleshoot network issues is to run a container within the context of a Docker Network. we can use it to test connectivity and gather information.
8+
9+
Netshoot is an image that come with a variety of network troubleshoot tools.
10+
we can run netshoot by using the container image nicolaka/netshoot
11+
we can even run netshoot within the network namespace of an existing container!
12+
13+
more Info: https://success.docker.com/article/troubleshooting-container-networking

docker/swarm/backup-restore-swarm.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

docker/swarm/docker-service.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
what is docker service ?
2+
3+
A service is used to run an application on a Docker Swarm. A service specifies a set of one or more replica tasks. These tasks will be distributed automatically acorss the nodes in the cluster and executed as containers.
4+
=====================================================================================================
5+
6+
how to create a service in docker swarm
7+
8+
docker service create --name mysvc --replicas 4 -p 9080:8080 tomcat
9+
docker service ls
10+
docker service mysvc ps
11+
docker service inspect mysvc
12+
docker service inspect --pretty mysvc
13+
docker service rm mysvc
14+
15+
various options while creating service
16+
17+
docker service create --name mysvc --replicas 2 -p 9080:80 -d nginx
18+
docker service create --name nginxsvc --replicas 2 --replicas-max-per-node 1 nginx
19+
docker service create --name nginxsvc --replicas 3 --mount type=volume,destination=/path/in/container nginx:alpine
20+
docker service create --name tomcatsvc --replicas 3 --constraint 'node.labels.type == queue' tomcat
21+
22+
======================================================================================================
23+
24+
Updating Service
25+
26+
update service with new image ( rolling update )
27+
docker service update --image=tomcat <serivename/id>
28+
29+
updating service with new network
30+
docker service update --network-add myoverlay <servicename/id>
31+
32+
updating/adding service port after creating a service
33+
docker service update --publish-add 9080:80 <servicename/id>
34+
35+
updating/adding mount on service after creating service
36+
docker service update --mount-add source=abc,target=/tmp <servicename/id>
37+
docker service update --mount-add type=volume,source=abc,target=/tmp <servicename/id>
38+
39+
======================================================================================================
40+
Different ways to scale a service:
41+
42+
docker service update --replicas 3 nginx
43+
docker service scale nginx=4

docker/swarm/docker-stack.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Docker Stacks:
2+
Services are capable of running single repicated application across nodes in the cluster, but what if you need to deploy a more complex application consisting of multiple services ?
3+
4+
A Stack is a collection of interrelated services that can be deployed and sclaed as a unit.
5+
===================================================================================================
6+
7+
create services in swarm using compose file ( declarative model )
8+
9+
docker stack deploy -c compose.yml mystack
10+
docker stack ls
11+
docker stack ps mystack
12+
docker stack services mystack
13+
docker stack rm mystack
14+
docker service scale mysvc=3

docker/swarm/readme.txt

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)