-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker.txt
More file actions
137 lines (102 loc) · 5.12 KB
/
docker.txt
File metadata and controls
137 lines (102 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
docker --version // to check docker version
docker run hello-world // to run an image in a container. if not present it will pull from docker hub
docker run --name DragonEmperor9480 <image_name>// to specifically name a container
docker run -it <image_name> //to run the docker container in interactive mode and terminal mode
docker run -d <image_name> // run it in background
docker attach <container_id> //attach back to container
docker run <image_name> sleep 100 // let the container run for specific time before it exits
docker pull <container> //only pull the container not run it
docker ps //list the running containers
docker ps -a //list all the containers
docker rm <container_id or name> //to remove the container
docker images // to list all the images
docker rmi <image_name> // delete the image
docker run ubuntu cat /etc/*release* // run the command inside ubuntu like executing a single command
docker run ubuntu 16:04 // here ":" is called a tag to use a specific version of a software
docker log <container_id or name> // to check logs of a container
docker stop <container_id> // to stop a running container
docker inspect // to check information about docker container
docker history
docker build Dockerfile -t DragonEmperor/my-custom-app // cmd to build a custom docker image
docker run --cpu=.5 ubuntu // dosent let the container take more than 50% of cpu
docker run --memory=100m ubuntu //dosent let the container use more than 100MB
docker volume create data_volume //creates a persistent volume where we can store data on the host machine
docker run -v data_volume:/var/lib/mysql mysql //mounts the above created colume to container
docker run -v /data/mysql:/var/lib/mysql mysql //can mount any dir by specifiying full name of it
//the above command is old way the new way is as follows
//the above two commands are old way the new command is as follows:
docker run \ --mount type=bind,source=/data/mysql,target=/var/lib/mysql mysql
--Docker Storage
the data of docker is stored in:
/var/lib/docker:
-aufs
-containers
-image
-volumes
--Storage Drivers
AUFS
ZFS
BTRFS
Device Manager
Overlay
Overlay2
--DOCKER NETWORKS
docker network ls // list the docker networks
docker network inspect bridge // bridge here is the name of the network we are inspecting
--Default Networks
Bridge -> docker run ubuntu
none-> docker run ubuntu --network=none
host->docker run ubuntu --network=host
--User-Defined Networks
docker network create \
--driver bridge \
--subnet 182.18.0.0/16
custom-isolated-network
--Example: Create a new network named wp-mysql-network using the bridge driver. Allocate subnet 182.18.0.0/24. Configure Gateway 182.18.0.1
soln: docker network create --driver bridge --subnet 182.18.0.0/24 --gateway 182.18.0.1 wp-mysql-network
Inspect the created network by docker network inspect wp-mysql-network
--Example: Deploy a mysql database using the mysql:5.6 image and name it mysql-db. Attach it to the newly created network wp-mysql-network
Set the database password to use db_pass123. The environment variable to set is MYSQL_ROOT_PASSWORD.
soln: docker run --name mysql-db -e MYSQL_ROOT_PASSWORD=db_pass123 --network wp-mysql-network mysql:5.6
--Container Orchestration
Container Orchestration allows you to run multiple thousands of instances in a single command. can also scale up and scale down based on the load.
--Docker Swarm
Combines multiple Docker machines together in a single cluster
for swarm manager: docker swarm init
for node worker: docker swarm join --token <token>
docker service create --relicas=3 my-web-server
we can have multiple manager nodes
a single manager node can be allowed to make decisions, its called leader.
--Raft Consensys algorithm
it uses random timers for initiating requests.
the first one to finish the timer sends out a request, requesting permisson to be the leader.the other managers on reciving the request responmd with their role.
then the leader is decided.
--Quorum
it is defined as the minimum number of members in assembly that must be present in any of the meeting.
Formula: (N+1)/2 where N is number of managers.
Fault Tolerance of N = (N-1)/2
usually docker dosent recommend no more than 7 managers
--Docker Compose
https://docs.docker.com/compose/
https://docs.docker.com/engine/reference/commandline/compose/
https://github.com/dockersamples/example-voting-app
--Docker Engiene
it is referred to the host with Docker installed on it.
mainly 3 components are installed
-Docker CLI
-Rest API
-Docker Daemon
Docker CLI can run on a different machine too,
the command example for it is: docker -H=remote-docker-engiene:2375
docker exec <container_id> ps -eaf // lists all the processes of that specific container
--Docker Info
docker info //lists all the information about the docker installed on the system
docker info | more // lists more info on docker
--Docker History
If you would like to know how a docker image is built you can use following command.
docker history <image_id>
--Docker Service
docker service ls // list the services
docker service create --replicas 3 my-web-server
docker service create --mode global my-antivirus
docker service update <container_name> replicas 4 // increase replicas