Skip to content

Commit 0c700af

Browse files
committed
更新文档说明
1 parent 76f8bf1 commit 0c700af

5 files changed

Lines changed: 251 additions & 11 deletions

File tree

Docker.md

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
## Docker
2+
3+
基础概念
4+
5+
- Images(镜像):Docker可以通过Pull和Push命令构建对象到服务中心
6+
- Containers(容器):Docker可以通过Start/Stop命令管理容器的生命周期
7+
- Logging(日志):Docker可以通过stdout,stderro捕获输出所有的容器内部信息
8+
- Volumes(存储):Docker可以创建和管理容器的相关文件存储
9+
- Networking(网络):Docker可以创建管理虚拟的接口和内部所有容器之间的网络桥接
10+
- RPC:Docker服务器提供允许外部程序去控制所有容器的行为的API
11+
12+
13+
配置加速器
14+
15+
注册:[配置 Docker 加速器](https://www.daocloud.io/mirror#accelerator-doc)
16+
17+
配置:
18+
```
19+
$ curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sudo sh -s http://12248bc3.m.daocloud.io
20+
```
21+
22+
23+
安装
24+
25+
参考:https://docs.docker.com/engine/installation/
26+
27+
```
28+
$ curl -sSL https://get.daocloud.io/docker | sh
29+
```
30+
31+
```
32+
If you would like to use Docker as a non-root user, you should now consider
33+
adding your user to the "docker" group with something like:
34+
35+
sudo usermod -aG docker zhanghe
36+
37+
Remember that you will have to log out and back in for this to take effect!
38+
```
39+
40+
41+
检查 docker 守护进程状态
42+
```
43+
$ sudo service docker status
44+
```
45+
46+
```
47+
docker start/running, process 1650
48+
```
49+
50+
51+
获取当前 docker 版本
52+
```
53+
$ sudo docker version
54+
```
55+
56+
```
57+
Client:
58+
Version: 1.12.1
59+
API version: 1.24
60+
Go version: go1.6.3
61+
Git commit: 23cf638
62+
Built: Thu Aug 18 05:22:43 2016
63+
OS/Arch: linux/amd64
64+
65+
Server:
66+
Version: 1.12.1
67+
API version: 1.24
68+
Go version: go1.6.3
69+
Git commit: 23cf638
70+
Built: Thu Aug 18 05:22:43 2016
71+
OS/Arch: linux/amd64
72+
```
73+
74+
75+
查看当前 docker 信息
76+
```
77+
$ sudo docker info
78+
```
79+
80+
```
81+
Containers: 0
82+
Running: 0
83+
Paused: 0
84+
Stopped: 0
85+
Images: 0
86+
Server Version: 1.12.1
87+
Storage Driver: aufs
88+
Root Dir: /var/lib/docker/aufs
89+
Backing Filesystem: extfs
90+
Dirs: 0
91+
Dirperm1 Supported: false
92+
Logging Driver: json-file
93+
Cgroup Driver: cgroupfs
94+
Plugins:
95+
Volume: local
96+
Network: host null bridge overlay
97+
Swarm: inactive
98+
Runtimes: runc
99+
Default Runtime: runc
100+
Security Options: apparmor
101+
Kernel Version: 3.13.0-97-generic
102+
Operating System: Ubuntu 14.04.5 LTS
103+
OSType: linux
104+
Architecture: x86_64
105+
CPUs: 4
106+
Total Memory: 7.756 GiB
107+
Name: ThinkPad-L421
108+
ID: XACY:MKNQ:Q7Q7:7JBI:JH3W:GISV:DIZO:QS7U:ERD2:XQHB:5JRK:3NCW
109+
Docker Root Dir: /var/lib/docker
110+
Debug Mode (client): false
111+
Debug Mode (server): false
112+
Registry: https://index.docker.io/v1/
113+
WARNING: No swap limit support
114+
Insecure Registries:
115+
127.0.0.0/8
116+
```
117+
118+
119+
搜索可用 docker 镜像
120+
```
121+
$ sudo docker search ubuntu
122+
```
123+
124+
```
125+
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
126+
ubuntu Ubuntu is a Debian-based Linux operating s... 4758 [OK]
127+
ubuntu-upstart Upstart is an event-based replacement for ... 66 [OK]
128+
rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 42 [OK]
129+
ubuntu-debootstrap debootstrap --variant=minbase --components... 27 [OK]
130+
torusware/speedus-ubuntu Always updated official Ubuntu docker imag... 27 [OK]
131+
nickistre/ubuntu-lamp LAMP server on Ubuntu 9 [OK]
132+
nuagebec/ubuntu Simple always updated Ubuntu docker images... 8 [OK]
133+
nickistre/ubuntu-lamp-wordpress LAMP on Ubuntu with wp-cli installed 6 [OK]
134+
nimmis/ubuntu This is a docker images different LTS vers... 5 [OK]
135+
maxexcloo/ubuntu Base image built on Ubuntu with init, Supe... 2 [OK]
136+
darksheer/ubuntu Base Ubuntu Image -- Updated hourly 1 [OK]
137+
admiringworm/ubuntu Base ubuntu images based on the official u... 1 [OK]
138+
jordi/ubuntu Ubuntu Base Image 1 [OK]
139+
datenbetrieb/ubuntu custom flavor of the official ubuntu base ... 0 [OK]
140+
lynxtp/ubuntu https://github.com/lynxtp/docker-ubuntu 0 [OK]
141+
webhippie/ubuntu Docker images for ubuntu 0 [OK]
142+
life360/ubuntu Ubuntu is a Debian-based Linux operating s... 0 [OK]
143+
esycat/ubuntu Ubuntu LTS 0 [OK]
144+
widerplan/ubuntu Our basic Ubuntu images. 0 [OK]
145+
teamrock/ubuntu TeamRock's Ubuntu image configured with AW... 0 [OK]
146+
ustclug/ubuntu ubuntu image for docker with USTC mirror 0 [OK]
147+
konstruktoid/ubuntu Ubuntu base image 0 [OK]
148+
dorapro/ubuntu ubuntu image 0 [OK]
149+
uvatbc/ubuntu Ubuntu images with unprivileged user 0 [OK]
150+
gopex/ubuntu Automatic build of GoPex customization ove... 0 [OK]
151+
```
152+
153+
154+
下载 ubuntu 官方镜像
155+
```
156+
$ sudo docker pull ubuntu
157+
```
158+
159+
下载中
160+
```
161+
Using default tag: latest
162+
latest: Pulling from library/ubuntu
163+
ff1f1f1de862: Downloading [===========================> ] 27.43 MB/49.79 MB
164+
0c7b035e2a1a: Download complete
165+
ac8ee255ff41: Download complete
166+
bf3d47be55f8: Download complete
167+
22a909724a97: Download complete
168+
```
169+
下载完成
170+
```
171+
Using default tag: latest
172+
latest: Pulling from library/ubuntu
173+
ff1f1f1de862: Pull complete
174+
0c7b035e2a1a: Pull complete
175+
ac8ee255ff41: Pull complete
176+
bf3d47be55f8: Pull complete
177+
22a909724a97: Pull complete
178+
Digest: sha256:3235a49037919e99696d97df8d8a230717272d848ee4ddadbca8d54f97ee30cb
179+
Status: Downloaded newer image for ubuntu:latest
180+
```
181+
182+
183+
查看当前镜像列表
184+
```
185+
$ sudo docker images
186+
```
187+
188+
```
189+
REPOSITORY TAG IMAGE ID CREATED SIZE
190+
ubuntu latest 45bc58500fa3 6 days ago 126.9 MB
191+
hello-world latest c54a2cc56cbb 12 weeks ago 1.848 kB
192+
```
193+
194+
195+
显示所有容器
196+
```
197+
$ sudo docker ps # 显示状态为运行中(Up)的
198+
$ sudo docker ps -a # 显示所有容器,包括运行中(Up)的和退出的(Exited)
199+
```
200+
201+
```
202+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
203+
accbcfa5e2e6 hello-world "/hello" 15 hours ago Exited (0) 15 hours ago angry_bhabha
204+
```
205+
206+
207+
删除容器
208+
```
209+
$ sudo docker rm angry_bhabha
210+
```
211+

Linux.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ ubuntu 解压 RAR
386386
$ sudo apt-get install p7zip-rar
387387
```
388388

389+
ubuntu 解压 windows 的 zip 文件出现乱码
390+
```
391+
$ sudo apt-get install unar
392+
$ unar file.zip
393+
```
394+
389395
统计当前目录下指定后缀名的文件总个数命令
390396
```
391397
$ find . -name "*.html" | wc -l
@@ -405,6 +411,8 @@ SSH 免密登陆远程主机
405411

406412
将本机公钥添加到对方 authorized_keys 中
407413
```
414+
$ ssh-copy-id user@host
415+
or
408416
$ ssh user@host 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub
409417
```
410418
注意权限设置:

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,13 @@ $ sudo apt-get install libmysqlclient-dev python-dev
553553
```
554554
$ sudo apt-get install libmariadbclient-dev
555555
```
556+
如果没有安装mysql/mariadb服务,还需要提前安装:
557+
```
558+
$ sudo apt-get install libmysqld-dev
559+
or
560+
$ sudo apt-get install libmariadbd-dev
561+
```
562+
556563

557564
说明:
558565
python版本的MySQL库(不建议使用这个)
@@ -599,6 +606,8 @@ $ sudo pip install psycopg2
599606
$ sudo su postgres
600607
或者
601608
$ sudo su - postgres
609+
# Mac下切换
610+
$ sudo su _postgres
602611
# 登录postgres数据库
603612
$ psql postgres
604613
# 提示如下:
@@ -860,6 +869,8 @@ field field
860869

861870
[ElasticSearch中文指南](http://www.elasticsearch.cn/guide/)
862871

872+
[Elasticsearch 权威指南(中文版)](http://es.xiaoleilu.com/)
873+
863874
[Python Elasticsearch Client](http://elasticsearch-py.readthedocs.org/en/latest/)
864875

865876
[PyES - Python Elastic Search](http://pyes.readthedocs.org/en/latest/index.html)

tools/convert.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def test():
6969
print oct(0), oct(1), oct(255) # 0 01 0377
7070
# 十进制转十六进制
7171
print hex(0), hex(1), hex(255) # 0x0 0x1 0xff
72+
# ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0a', '0b', '0c', '0d', '0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', '2f', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3a', '3b', '3c', '3d', '3e', '3f', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', '5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '8a', '8b', '8c', '8d', '8e', '8f', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '9a', '9b', '9c', '9d', '9e', '9f', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'ba', 'bb', 'bc', 'bd', 'be', 'bf', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'ca', 'cb', 'cc', 'cd', 'ce', 'cf', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'da', 'db', 'dc', 'dd', 'de', 'df', 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'ea', 'eb', 'ec', 'ed', 'ee', 'ef', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'fa', 'fb', 'fc', 'fd', 'fe', 'ff']
73+
print [hex(i).lstrip('0x').zfill(2) for i in range(0, 256)]
7274

7375
if __name__ == "__main__":
7476
test()

tools/date.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
__author__ = 'zhanghe'
33

44
import time
5-
import datetime
5+
from datetime import datetime, timedelta
6+
from pytz import timezone, utc
67

78

89
def add_time(time_str, second):
@@ -115,13 +116,13 @@ def test():
115116
# 日期时间元祖 datetime tuple(datetime obj)
116117
# MySql中DATETIME类型 对应的就是 python里的这种类型
117118
# 注意与时间元祖的区别
118-
print datetime.datetime.now() # 2015-09-07 22:15:03.419781
119-
print type(datetime.datetime.now()) # <type 'datetime.datetime'>
119+
print datetime.now() # 2015-09-07 22:15:03.419781
120+
print type(datetime.now()) # <type 'datetime.datetime'>
120121

121122
# 日期时间元祖 转为 时间元祖
122123
# date.timetuple():返回日期对应的time.struct_time对象
123-
print datetime.datetime.now().timetuple() # time.struct_time(tm_year=2015, tm_mon=9, tm_mday=7, tm_hour=22, tm_min=18, tm_sec=22, tm_wday=0, tm_yday=250, tm_isdst=-1)
124-
print type(datetime.datetime.now().timetuple()) # <type 'time.struct_time'>
124+
print datetime.now().timetuple() # time.struct_time(tm_year=2015, tm_mon=9, tm_mday=7, tm_hour=22, tm_min=18, tm_sec=22, tm_wday=0, tm_yday=250, tm_isdst=-1)
125+
print type(datetime.now().timetuple()) # <type 'time.struct_time'>
125126

126127
# 字符串日期转星期(星期(0-6),星期天为星期的开始)
127128
print time.strftime('%w', time.strptime('2016-01-17', '%Y-%m-%d'))
@@ -130,21 +131,28 @@ def test():
130131
print time.strftime('%Y-%m-%d %H:%M:%S', time.strptime('5/6/2016 10:02:47 PM', '%m/%d/%Y %I:%M:%S %p'))
131132

132133
# 当前年份(4位)
133-
print datetime.datetime.now().year
134+
print datetime.now().year
134135

135136
# 获取2个月之后的日期
136-
print datetime.datetime.now() + datetime.timedelta(days=60)
137+
print datetime.now() + timedelta(days=60)
137138

138139
# 显示友好时间
139140
print time_pretty(60 * 60 * 24 * 3 + 60 * 60 * 2 + 60 * 3)
140141

141142
# 字符串转对象
142-
print datetime.datetime.strptime('2016-06-06', "%Y-%m-%d").date(), type(datetime.datetime.strptime('2016-06-06', "%Y-%m-%d").date())
143-
print datetime.datetime.strptime('2016-06-06 12:34:54', "%Y-%m-%d %H:%M:%S")
144-
# print datetime.datetime.strptime('2016-06', "%Y-%m-%d %H:%M:%S") # 异常ValueError
143+
print datetime.strptime('2016-06-06', "%Y-%m-%d").date(), type(datetime.strptime('2016-06-06', "%Y-%m-%d").date())
144+
print datetime.strptime('2016-06-06 12:34:54', "%Y-%m-%d %H:%M:%S")
145+
# print datetime.strptime('2016-06', "%Y-%m-%d %H:%M:%S") # 异常ValueError
145146

146147
# 显示毫秒
147-
print datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
148+
print datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
149+
150+
# iso时间
151+
print datetime.utcnow().isoformat()
152+
print datetime.utcnow().date().isoformat()
153+
print datetime(2002, 10, 27, 12, 0, 0, tzinfo=utc).strftime('%Y-%m-%dT%H:%M:%S%Z%z')
154+
print datetime.now().replace(microsecond=0, tzinfo=utc)
155+
print datetime.fromtimestamp(0, timezone('Asia/Shanghai'))
148156

149157

150158
if __name__ == "__main__":

0 commit comments

Comments
 (0)