Skip to content

Commit 0811938

Browse files
update
1 parent e245e75 commit 0811938

File tree

3 files changed

+178
-3
lines changed

3 files changed

+178
-3
lines changed

note/c++11多线程.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,14 @@ int main()
614614
---
615615
## 参考
616616
617-
* C++并发编程(中文版) https://legacy.gitbook.com/book/chenxiaowei/cpp_concurrency_in_action/details
617+
* C++并发编程(中文版)
618+
619+
https://legacy.gitbook.com/book/chenxiaowei/cpp_concurrency_in_action/details
618620
619621
* cppreference
620622
621623
https://en.cppreference.com/w/cpp/thread
622624
623-
* 腾讯学堂的一个视频也不错
625+
* 现代 C++ 教程:高速上手 C++ 11/14/17/20
624626
625-
https://ke.qq.com/course/131596
627+
https://changkun.de/modern-cpp/zh-cn/07-thread/

note/docker.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,185 @@ dd5b26affce3 nginx "bash" 26 minutes ago
106106
docker exec -it my_nginx bash
107107
```
108108

109+
------
109110

111+
### 例子
112+
```
113+
# 运行一个redis镜像
114+
sudo docker run -d -p 6379:6379 --name redis redis:latest
115+
116+
# 关闭容器
117+
docker stop container-id
118+
119+
# 查看名字
120+
docker images
121+
REPOSITORY TAG IMAGE ID CREATED SIZE
122+
redis latest 2f66aad5324a 12 days ago 117MB
123+
124+
# 启动
125+
docker start redis
126+
127+
# 进入容器
128+
docker exec -it redis /bin/bash
129+
docker exec -it <容器ID> /bin/bash
130+
131+
# 执行redis客户端
132+
redis-cli
133+
127.0.0.1:6379>
134+
135+
```
136+
```
137+
# 查看
138+
docker ps 查看当前运行中的容器
139+
docker images 查看镜像列表
140+
docker rm container-id 删除指定 id 的容器
141+
docker stop/start container-id 停止/启动指定 id 的容器
142+
docker rmi image-id 删除指定 id 的镜像
143+
docker volume ls 查看 volume 列表
144+
docker network ls 查看网络列表
145+
```
146+
147+
* 交互式
148+
```
149+
docker run -i -t ubuntu:15.10 /bin/bash
150+
151+
各个参数解析:
152+
-t: 在新容器内指定一个伪终端或终端。
153+
-i: 允许你对容器内的标准输入 (STDIN) 进行交互。
154+
```
155+
156+
* 查看日志
157+
```
158+
# 启动一个docker
159+
docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"
160+
161+
# 查看日志
162+
docker logs <容器ID>
163+
docker logs -f <容器ID>
164+
```
165+
166+
* 查看网络端口映射
167+
```
168+
docker port <容器ID>
169+
```
170+
171+
* top查看
172+
```
173+
docker top <容器ID>
174+
UID PID PPID C STIME TTY TIME CMD
175+
root 5695 30047 0 19:23 ? 00:00:00 sleep 1
176+
root 30047 30025 0 18:59 ? 00:00:00 /bin/sh -c while true; do echo hello world; sleep 1; done
177+
```
178+
179+
* 镜像
180+
```
181+
$ docker pull hello-world
182+
Using default tag: latest
183+
latest: Pulling from library/hello-world
184+
2db29710123e: Pull complete
185+
Digest: sha256:6e8b6f026e0b9c419ea0fd02d3905dd0952ad1feea67543f525c73a0a790fefb
186+
Status: Downloaded newer image for hello-world:latest
187+
docker.io/library/hello-world:latest
188+
189+
$ docker images
190+
REPOSITORY TAG IMAGE ID CREATED SIZE
191+
redis latest 2f66aad5324a 12 days ago 117MB
192+
hello-world latest feb5d9fea6a5 17 months ago 13.3kB
193+
ubuntu 15.10 9b9cb95443b5 6 years ago 137MB
194+
195+
# 运行
196+
$ docker run hello-world
197+
198+
# 删除
199+
$ docker rmi hello-world
200+
```
201+
202+
----
110203

204+
### Dockerfile
205+
在dockerfile所在的目录执行docker build命令,构建自己的docker镜像。
206+
```
207+
docker build -t test:v1 .
208+
-t 设置镜像名字和版本号 // 这里指的是镜像名称是test,版本是v1
209+
```
210+
211+
### 目录挂载
212+
* bind mount 直接把宿主机目录映射到容器内,适合挂代码目录和配置文件。可挂到多个容器上
213+
* volume 由容器创建和管理,创建在宿主机,所以删除容器不会丢失,官方推荐,更高效,Linux 文件系统,适合存储数据库数据。可挂到多个容器上
214+
* tmpfs mount 适合存储临时文件,存宿主机内存中。不可多容器共享。
215+
```
216+
docker run -p 8080:8080 --name test-hello -v D:/code:/app -d test:v1
217+
```
218+
219+
### 虚拟网络--多容器通信
220+
```
221+
# 创建一个名为test-net的网络
222+
docker network create test-net
223+
224+
# 运行 Redis 在 test-net 网络中,别名redis
225+
docker run -d --name redis --network test-net --network-alias redis redis:latest
226+
```
227+
228+
### Docker-Compose
229+
* docker-compose 把项目的多个服务集合到一起,一键运行
230+
* 在docker-compose.yml 文件所在目录,执行:docker-compose up就可以跑起来了
231+
232+
```
233+
在后台运行只需要加一个 -d 参数docker-compose up -d
234+
查看运行状态:docker-compose ps
235+
停止运行:docker-compose stop
236+
重启:docker-compose restart
237+
重启单个服务:docker-compose restart service-name
238+
进入容器命令行:docker-compose exec service-name sh
239+
查看容器运行log:docker-compose logs [service-name]
240+
```
241+
242+
---
243+
244+
#### kubernetes
245+
k8s可以干什么?
246+
* 当你的应用只是跑在一台机器,直接一个 docker + docker-compose 就够了,方便轻松;
247+
* 当你的应用需要跑在 3,4 台机器上,你依旧可以每台机器单独配置运行环境 + 负载均衡器;
248+
* 当你应用访问数不断增加,机器逐渐增加到十几台、上百台、上千台时,每次加机器、软件更新、版本回滚,都会变得非常麻烦。这时候Kubernetes 就可以一展身手了。
111249

250+
![tu](../pic/docker_1.png)
251+
252+
pdd是k8s调度、管理的最小单位,一个 Pod 可以包含一个或多个容器,每个 Pod 有自己的虚拟IP。一个工作节点可以有多个 pod,主节点会考量负载自动调度 pod 到哪个节点运行。
253+
254+
#### 安装
255+
```
256+
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
257+
sudo install minikube-linux-amd64 /usr/local/bin/minikube
258+
```
259+
260+
```
261+
minikube start --force --driver=docker
262+
263+
minikube kubectl
264+
265+
minikube kubectl -- get pods -A
266+
```
267+
268+
269+
* 工作负载分类
270+
* Deployment
271+
适合无状态应用,所有pod等价,可替代
272+
* StatefulSet
273+
有状态的应用,适合数据库这种类型。
274+
* DaemonSet
275+
在每个节点上跑一个 Pod,可以用来做节点监控、节点日志收集等
276+
* Job & CronJob
277+
Job 用来表达的是一次性的任务,而 CronJob 会根据其时间规划反复运行。
278+
279+
280+
----
112281

113282
## 参考
114283

115284
- [docker 入门到实践](https://yeasy.gitbooks.io/docker_practice/image/pull.html)
116285

117286
- [使用Docker快速搭建Nginx+PHP-FPM环境](https://www.jianshu.com/p/3384e342502b)
287+
288+
- [docker 教程](https://docker.easydoc.net/doc/81170005/cCewZWoN/XQEqNjiu)
289+
290+
- [k8s 教程](https://k8s.easydoc.net/docs/dRiQjyTY/28366845/6GiNOzyZ/9EX8Cp45)

pic/docker_1.png

731 KB
Loading

0 commit comments

Comments
 (0)