mirror of
https://github.com/yeasy/docker_practice.git
synced 2024-12-25 06:28:56 +00:00
Update appendix section
This commit is contained in:
parent
f2d6f998ab
commit
36ab0b9862
@ -1,6 +1,6 @@
|
||||
# Docker — 从入门到实践
|
||||
|
||||
0.7.4
|
||||
0.7.5
|
||||
|
||||
[Docker](http://www.docker.com) 是个划时代的开源项目,它彻底释放了虚拟化的威力,极大提高了应用的运行效率,降低了云计算资源供应的成本,同时让应用的部署、测试和分发都变得前所未有的高效和轻松!
|
||||
|
||||
@ -38,6 +38,8 @@
|
||||
|
||||
* 0.8.0: 2016-MM-DD
|
||||
* 修正文字内容
|
||||
* 根据最新版本修订安装使用
|
||||
* 补充附录章节
|
||||
|
||||
* 0.7.0: 2016-06-12
|
||||
* 根据最新版本进行命令调整
|
||||
|
24
SUMMARY.md
24
SUMMARY.md
@ -121,14 +121,16 @@
|
||||
* [原理与架构](mesos/architecture.md)
|
||||
* [配置项解析](mesos/configuration.md)
|
||||
* [常见框架](mesos/framework.md)
|
||||
* [附录一:命令查询](appendix_command/README.md)
|
||||
* [附录二:常见仓库介绍](appendix_repo/README.md)
|
||||
* [Ubuntu](appendix_repo/ubuntu.md)
|
||||
* [CentOS](appendix_repo/centos.md)
|
||||
* [MySQL](appendix_repo/mysql.md)
|
||||
* [MongoDB](appendix_repo/mongodb.md)
|
||||
* [Redis](appendix_repo/redis.md)
|
||||
* [Nginx](appendix_repo/nginx.md)
|
||||
* [WordPress](appendix_repo/wordpress.md)
|
||||
* [Node.js](appendix_repo/nodejs.md)
|
||||
* [附录三:有用的资源](appendix_resources/README.md)
|
||||
* [附录](appendix/README.md)
|
||||
* [附录一:常见问题总结](appendix/faq/README.md)
|
||||
* [附录二:热门镜像介绍](appendix/repo/README.md)
|
||||
* [Ubuntu](appendix/repo/ubuntu.md)
|
||||
* [CentOS](appendix/repo/centos.md)
|
||||
* [MySQL](appendix/repo/mysql.md)
|
||||
* [MongoDB](appendix/repo/mongodb.md)
|
||||
* [Redis](appendix/repo/redis.md)
|
||||
* [Nginx](appendix/repo/nginx.md)
|
||||
* [WordPress](appendix/repo/wordpress.md)
|
||||
* [Node.js](appendix/repo/nodejs.md)
|
||||
* [附录三:Docker 命令查询](appendix/command/README.md)
|
||||
* [附录四:资源链接](appendix/resources/README.md)
|
||||
|
1
appendix/README.md
Normal file
1
appendix/README.md
Normal file
@ -0,0 +1 @@
|
||||
# 附录
|
@ -1,56 +1,56 @@
|
||||
//dot -Tpng xx.dot -o xx.png
|
||||
digraph G {
|
||||
rankdir=TB;
|
||||
fontname = "Microsoft YaHei";
|
||||
fontsize = 14;
|
||||
penwidth = 3;
|
||||
compound=true;
|
||||
rankdir=LR;
|
||||
|
||||
node [shape = record];
|
||||
edge [fontname = "Arial", fontsize = 12, color="darkgreen" ];
|
||||
|
||||
image[label="Image",color=blue];
|
||||
registry[label="Registry",color=blue];
|
||||
tar[label="Tar files",color=blue];
|
||||
|
||||
subgraph cluster_container {
|
||||
label = "Container";
|
||||
style = "bold";
|
||||
color = blue;
|
||||
edge [fontname = "Arial", fontsize = 11, color="skyblue" ];
|
||||
//node [style=filled];
|
||||
run[label="Running",shape=circle, style=filled, fillcolor=green];
|
||||
stop[label="Stopped",shape=circle, style=filled, fillcolor=red];
|
||||
pause[label="Paused",shape=circle, style=filled, fillcolor=blue];
|
||||
|
||||
run->pause[label="pause"];
|
||||
pause->run[label="unpause"];
|
||||
run->run[label="restart"];
|
||||
run->stop[label="kill"];
|
||||
stop->run[label="start"];
|
||||
}
|
||||
|
||||
run->image[label="commit",ltail=cluster_container];
|
||||
image->run[label="start"];
|
||||
|
||||
image->tar[label="export|save"];
|
||||
tar->image[label="import"];
|
||||
|
||||
image->registry[label="push"];
|
||||
registry->image[label="pull"];
|
||||
|
||||
//heat[label="heat commands",color=blue];
|
||||
//heatshell[label="heatclient.shell.HeatShell",color=blue];
|
||||
//shell[label="{heatclient.v1.shell|+do_stack_create\l+do_stack_show\l+do_stack_update\l...\l+do_event_list\l...\l+do_resource_list\l...\l+do_resource_type_show\l...\l+do_template_show\l...\l}",color=blue];
|
||||
//heatclient[label="heatclient.client.Client",color=blue];
|
||||
//client[label="heatclient.v1.client.Client",color=blue];
|
||||
//httpclient[label="heatclient.common.http.HTTPClient",color=blue];
|
||||
|
||||
|
||||
|
||||
//openstackservices[label="{OpenStack Services|+Nova\l+Neutron\l+Keystone\l...}",color=blue];
|
||||
|
||||
//{rank=same; image cluster_container}
|
||||
//{rank=same; rpcproxy apimixin}
|
||||
}
|
||||
//dot -Tpng xx.dot -o xx.png
|
||||
digraph G {
|
||||
rankdir=TB;
|
||||
fontname = "Microsoft YaHei";
|
||||
fontsize = 14;
|
||||
penwidth = 3;
|
||||
compound=true;
|
||||
rankdir=LR;
|
||||
|
||||
node [shape = record];
|
||||
edge [fontname = "Arial", fontsize = 12, color="darkgreen" ];
|
||||
|
||||
image[label="Image",color=blue];
|
||||
registry[label="Registry",color=blue];
|
||||
tar[label="Tar files",color=blue];
|
||||
|
||||
subgraph cluster_container {
|
||||
label = "Container";
|
||||
style = "bold";
|
||||
color = blue;
|
||||
edge [fontname = "Arial", fontsize = 11, color="skyblue" ];
|
||||
//node [style=filled];
|
||||
run[label="Running",shape=circle, style=filled, fillcolor=green];
|
||||
stop[label="Stopped",shape=circle, style=filled, fillcolor=red];
|
||||
pause[label="Paused",shape=circle, style=filled, fillcolor=blue];
|
||||
|
||||
run->pause[label="pause"];
|
||||
pause->run[label="unpause"];
|
||||
run->run[label="restart"];
|
||||
run->stop[label="kill"];
|
||||
stop->run[label="start"];
|
||||
}
|
||||
|
||||
run->image[label="commit",ltail=cluster_container];
|
||||
image->run[label="start"];
|
||||
|
||||
image->tar[label="export|save"];
|
||||
tar->image[label="import"];
|
||||
|
||||
image->registry[label="push"];
|
||||
registry->image[label="pull"];
|
||||
|
||||
//heat[label="heat commands",color=blue];
|
||||
//heatshell[label="heatclient.shell.HeatShell",color=blue];
|
||||
//shell[label="{heatclient.v1.shell|+do_stack_create\l+do_stack_show\l+do_stack_update\l...\l+do_event_list\l...\l+do_resource_list\l...\l+do_resource_type_show\l...\l+do_template_show\l...\l}",color=blue];
|
||||
//heatclient[label="heatclient.client.Client",color=blue];
|
||||
//client[label="heatclient.v1.client.Client",color=blue];
|
||||
//httpclient[label="heatclient.common.http.HTTPClient",color=blue];
|
||||
|
||||
|
||||
|
||||
//openstackservices[label="{OpenStack Services|+Nova\l+Neutron\l+Keystone\l...}",color=blue];
|
||||
|
||||
//{rank=same; image cluster_container}
|
||||
//{rank=same; rpcproxy apimixin}
|
||||
}
|
93
appendix/_images/cmd_logic.dot.bak
Normal file
93
appendix/_images/cmd_logic.dot.bak
Normal file
@ -0,0 +1,93 @@
|
||||
//dot -Tpng cmd_logic.dot -o cmd_logic.png
|
||||
digraph G {
|
||||
rankdir=TB;
|
||||
rankdir=LR;
|
||||
nodesep=1;
|
||||
//ranksep=1
|
||||
fontname = "Microsoft YaHei";
|
||||
fontsize = 28;
|
||||
penwidth = 4;
|
||||
compound=true;
|
||||
|
||||
node [shape = record];
|
||||
edge [fontname = "Arial", fontsize = 20, color="darkgreen" ];
|
||||
|
||||
user[label="User",color=blue,shape=ellipse, style=filled, fillcolor=green];
|
||||
dockerfile[label="Dockerfile",color=blue];
|
||||
daemon[label="Daemon",color=blue];
|
||||
image[label="Image",color=blue];
|
||||
registry[label="Registry",color=blue];
|
||||
tar[label="Tar files",color=blue];
|
||||
network[label="Network",color=blue]
|
||||
service[label="Service",color=blue]
|
||||
swarm[label="Swarm",color=blue]
|
||||
volume[label="Volume",color=blue]
|
||||
|
||||
subgraph cluster_container {
|
||||
label = "Container";
|
||||
labelloc = "c";
|
||||
nodesep=.5;
|
||||
style = "bold";
|
||||
color = blue;
|
||||
edge [fontname = "Arial", fontsize = 20, color="skyblue" ];
|
||||
//node [style=filled];
|
||||
create[label="Created",shape=circle, style=filled, fillcolor=lightblue];
|
||||
run[label="Running",shape=circle, style=filled, fillcolor=green];
|
||||
pause[label="Paused",shape=circle, style=filled, fillcolor=blue];
|
||||
stop[label="Stopped",shape=circle, style=filled, fillcolor=red];
|
||||
exit[label="Exited",shape=circle, style=filled, fillcolor=gray];
|
||||
|
||||
create->run[label=<<i>start</i>>];
|
||||
run->pause[label="pause"];
|
||||
pause->run[label="unpause"];
|
||||
run->run[label="restart"];
|
||||
run->stop[label="stop"];
|
||||
run->exit[label="kill"];
|
||||
stop->run[label="start"];
|
||||
}
|
||||
|
||||
//dockerfile
|
||||
dockerfile->image[label="build"];
|
||||
|
||||
//container
|
||||
run->image[headlabel="commit", labeldistance=7.5, ltail=cluster_container];
|
||||
run->tar[label="export",ltail=cluster_container];
|
||||
run->network[label="connect | disconnect",ltail=cluster_container];
|
||||
|
||||
//image
|
||||
image->create[label="create"];
|
||||
image->run[label="run"];
|
||||
image->tar[label="save"];
|
||||
image->registry[label="push"];
|
||||
|
||||
//tar
|
||||
tar->image[label="import | load"];
|
||||
image->registry[label="push"];
|
||||
|
||||
//registry
|
||||
registry->image[label="pull"];
|
||||
|
||||
//network
|
||||
network->network[label="create | rm | ls | inspect"]
|
||||
|
||||
//user
|
||||
user->run[label="attach | cp | diff | exec | inspect | logs | ps | rename | rm | stats | top | update | wait",lhead=cluster_container]
|
||||
user->image[label="history | images | rmi | tag"]
|
||||
user->daemon[label="event | info | version"]
|
||||
user->registry[label="login | logout | search"]
|
||||
|
||||
//heat[label="heat commands",color=blue];
|
||||
//heatshell[label="heatclient.shell.HeatShell",color=blue];
|
||||
//shell[label="{heatclient.v1.shell|+do_stack_create\l+do_stack_show\l+do_stack_update\l...\l+do_event_list\l...\l+do_resource_list\l...\l+do_resource_type_show\l...\l+do_template_show\l...\l}",color=blue];
|
||||
//heatclient[label="heatclient.client.Client",color=blue];
|
||||
//client[label="heatclient.v1.client.Client",color=blue];
|
||||
//httpclient[label="heatclient.common.http.HTTPClient",color=blue];
|
||||
|
||||
|
||||
|
||||
//openstackservices[label="{OpenStack Services|+Nova\l+Neutron\l+Keystone\l...}",color=blue];
|
||||
|
||||
//{rank=same; image registry dockerfile tar}
|
||||
//{rank=same; container}
|
||||
//{rank=same; user}
|
||||
}
|
BIN
appendix/_images/cmd_logic.graffle/data.plist
Normal file
BIN
appendix/_images/cmd_logic.graffle/data.plist
Normal file
Binary file not shown.
BIN
appendix/_images/cmd_logic.graffle/image10.pdf
Normal file
BIN
appendix/_images/cmd_logic.graffle/image10.pdf
Normal file
Binary file not shown.
BIN
appendix/_images/cmd_logic.graffle/image11.pdf
Normal file
BIN
appendix/_images/cmd_logic.graffle/image11.pdf
Normal file
Binary file not shown.
BIN
appendix/_images/cmd_logic.graffle/image12.pdf
Normal file
BIN
appendix/_images/cmd_logic.graffle/image12.pdf
Normal file
Binary file not shown.
BIN
appendix/_images/cmd_logic.graffle/image13.pdf
Normal file
BIN
appendix/_images/cmd_logic.graffle/image13.pdf
Normal file
Binary file not shown.
BIN
appendix/_images/cmd_logic.graffle/image4.pdf
Normal file
BIN
appendix/_images/cmd_logic.graffle/image4.pdf
Normal file
Binary file not shown.
BIN
appendix/_images/cmd_logic.graffle/image5.pdf
Normal file
BIN
appendix/_images/cmd_logic.graffle/image5.pdf
Normal file
Binary file not shown.
BIN
appendix/_images/cmd_logic.graffle/image6.pdf
Normal file
BIN
appendix/_images/cmd_logic.graffle/image6.pdf
Normal file
Binary file not shown.
BIN
appendix/_images/cmd_logic.graffle/image7.pdf
Normal file
BIN
appendix/_images/cmd_logic.graffle/image7.pdf
Normal file
Binary file not shown.
BIN
appendix/_images/cmd_logic.graffle/image9.pdf
Normal file
BIN
appendix/_images/cmd_logic.graffle/image9.pdf
Normal file
Binary file not shown.
Before Width: | Height: | Size: 704 KiB After Width: | Height: | Size: 704 KiB |
51
appendix/_images/container_status.dot
Normal file
51
appendix/_images/container_status.dot
Normal file
@ -0,0 +1,51 @@
|
||||
//dot -Tpng container_status.dot -o container_status.png
|
||||
digraph G {
|
||||
rankdir=TB;
|
||||
rankdir=LR;
|
||||
nodesep=1;
|
||||
//ranksep=1
|
||||
fontname = "Microsoft YaHei";
|
||||
fontsize = 28;
|
||||
penwidth = 4;
|
||||
compound=true;
|
||||
style = "bold";
|
||||
color = blue;
|
||||
|
||||
node [shape = record];
|
||||
edge [fontname = "Arial", fontsize = 20, color="darkgreen" ];
|
||||
image[label="Image",color=blue];
|
||||
image->create[label="create"];
|
||||
image->run[label="run"];
|
||||
|
||||
edge [fontname = "Arial", fontsize = 20, color="skyblue" ];
|
||||
//node [style=filled];
|
||||
create[label="Created",shape=circle, style=filled, fillcolor=lightblue];
|
||||
run[label="Running",shape=circle, style=filled, fillcolor=green];
|
||||
pause[label="Paused",shape=circle, style=filled, fillcolor=blue];
|
||||
stop[label="Stopped",shape=circle, style=filled, fillcolor=red];
|
||||
exit[label="Exited",shape=circle, style=filled, fillcolor=gray];
|
||||
|
||||
create->run[label=<<i>start</i>>];
|
||||
run->pause[label="pause"];
|
||||
pause->run[label="unpause"];
|
||||
run->run[label="restart"];
|
||||
run->stop[label="stop"];
|
||||
run->exit[label="kill"];
|
||||
stop->run[label="start"];
|
||||
|
||||
|
||||
//heat[label="heat commands",color=blue];
|
||||
//heatshell[label="heatclient.shell.HeatShell",color=blue];
|
||||
//shell[label="{heatclient.v1.shell|+do_stack_create\l+do_stack_show\l+do_stack_update\l...\l+do_event_list\l...\l+do_resource_list\l...\l+do_resource_type_show\l...\l+do_template_show\l...\l}",color=blue];
|
||||
//heatclient[label="heatclient.client.Client",color=blue];
|
||||
//client[label="heatclient.v1.client.Client",color=blue];
|
||||
//httpclient[label="heatclient.common.http.HTTPClient",color=blue];
|
||||
|
||||
|
||||
|
||||
//openstackservices[label="{OpenStack Services|+Nova\l+Neutron\l+Keystone\l...}",color=blue];
|
||||
|
||||
//{rank=same; image registry dockerfile tar}
|
||||
//{rank=same; container}
|
||||
//{rank=same; user}
|
||||
}
|
BIN
appendix/_images/container_status.png
Normal file
BIN
appendix/_images/container_status.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 67 KiB |
126
appendix/command/README.md
Normal file
126
appendix/command/README.md
Normal file
@ -0,0 +1,126 @@
|
||||
# Docker 命令查询
|
||||
|
||||
## 基本语法
|
||||
Docker 命令有两大类,客户端命令和服务端命令。前者是主要的操作接口,后者用来启动 Docker daemon。
|
||||
|
||||
* 客户端命令:基本命令格式为 `docker [OPTIONS] COMMAND [arg...]`;
|
||||
* 服务端命令:基本命令格式为 `docker daemon [OPTIONS]`。
|
||||
|
||||
可以通过 `man docker` 或 `docker help` 来查看这些命令。
|
||||
|
||||
## 客户端命令选项
|
||||
|
||||
* --config="":指定客户端配置文件,默认为 `/.docker`;
|
||||
* -D=true|false:是否使用 debug 模式。默认不开启;
|
||||
* -H, --host=[]:指定命令对应 Docker daemon 的监听接口,可以为 unix 套接字(unix:///path/to/socket),文件句柄(fd://socketfd)或 tcp 套接字(tcp://[host[:port]]),默认为 unix:///var/run/docker.sock;
|
||||
* -l, --log-level="debug|info|warn|error|fatal":指定日志输出级别;
|
||||
* --tls=true|false:是否对 Docker daemon 启用 TLS 安全机制,默认为否;
|
||||
* --tlscacert= /.docker/ca.pem:TLS CA 签名的可信证书文件路径;
|
||||
* --tlscert= /.docker/cert.pem:TLS 可信证书文件路径;
|
||||
* --tlscert= /.docker/key.pem:TLS 密钥文件路径;
|
||||
* --tlsverify=true|false:启用 TLS 校验,默认为否。
|
||||
|
||||
## daemon 命令选项
|
||||
* --api-cors-header="":CORS 头部域,默认不允许 CORS,要允许任意的跨域访问,可以指定为 “*”;
|
||||
* --authorization-plugin="":载入认证的插件;
|
||||
* -b="":将容器挂载到一个已存在的网桥上。指定为 'none' 时则禁用容器的网络,与 --bip 选项互斥;
|
||||
* --bip="":让动态创建的 docker0 网桥采用给定的 CIDR 地址; 与 -b 选项互斥;
|
||||
* --cgroup-parent="":指定 cgroup 的父组,默认 fs cgroup 驱动为 `/docker`,systemd cgroup 驱动为 `system.slice`;
|
||||
* --cluster-store="":构成集群(如 Swarm)时,集群键值数据库服务地址;
|
||||
* --cluster-advertise="":构成集群时,自身的被访问地址,可以为 `host:port` 或 `interface:port`;
|
||||
* --cluster-store-opt="":构成集群时,键值数据库的配置选项;
|
||||
* --config-file="/etc/docker/daemon.json":daemon 配置文件路径;
|
||||
* --containerd="":containerd 文件的路径;
|
||||
* -D, --debug=true|false:是否使用 Debug 模式。缺省为 false;
|
||||
* --default-gateway="":容器的 IPv4 网关地址,必须在网桥的子网段内;
|
||||
* --default-gateway-v6="":容器的 IPv6 网关地址;
|
||||
* --default-ulimit=[]:默认的 ulimit 值;
|
||||
* --disable-legacy-registry=true|false:是否允许访问旧版本的镜像仓库服务器;
|
||||
* --dns="":指定容器使用的 DNS 服务器地址;
|
||||
* --dns-opt="":DNS 选项;
|
||||
* --dns-search=[]:DNS 搜索域;
|
||||
* --exec-opt=[]:运行时的执行选项;
|
||||
* --exec-root="":容器执行状态文件的根路径,默认为 `/var/run/docker`;
|
||||
* --fixed-cidr="":限定分配 IPv4 地址范围;
|
||||
* --fixed-cidr-v6="":限定分配 IPv6 地址范围;
|
||||
* -G, --group="":分配给 unix 套接字的组,默认为 `docker`;
|
||||
* -g, --graph="":Docker 运行时的根路径,默认为 `/var/lib/docker`;
|
||||
* -H, --host=[]:指定命令对应 Docker daemon 的监听接口,可以为 unix 套接字(unix:///path/to/socket),文件句柄(fd://socketfd)或 tcp 套接字(tcp://[host[:port]]),默认为 unix:///var/run/docker.sock;
|
||||
* --icc=true|false:是否启用容器间以及跟 daemon 所在主机的通信。默认为 true。
|
||||
* --insecure-registry=[]:允许访问给定的非安全仓库服务;
|
||||
* --ip="":绑定容器端口时候的默认 IP 地址。缺省为 0.0.0.0;
|
||||
* --ip-forward=true|false:是否检查启动在 Docker 主机上的启用 IP 转发服务,默认开启。注意关闭该选项将不对系统转发能力进行任何检查修改;
|
||||
* --ip-masq=true|false:是否进行地址伪装,用于容器访问外部网络,默认开启;
|
||||
* --iptables=true|false:是否允许 Docker 添加 iptables 规则。缺省为 true;
|
||||
* --ipv6=true|false:是否启用 IPv6 支持,默认关闭;
|
||||
* -l, --log-level="debug|info|warn|error|fatal":指定日志输出级别;
|
||||
* --label="[]":添加指定的键值对标注;
|
||||
* --log-driver="json-file|syslog|journald|gelf|fluentd|awslogs|splunk|etwlogs|gcplogs|none":指定日志后端驱动,默认为 json-file;
|
||||
* --log-opt=[]:日志后端的选项;
|
||||
* --mtu=VALUE:指定容器网络的 mtu;
|
||||
* -p="":指定 daemon 的 PID 文件路径。缺省为 `/var/run/docker.pid`;
|
||||
* --raw-logs:输出原始,未加色彩的日志信息;
|
||||
* --registry-mirror=<scheme>://<host>:指定 `docker pull` 时使用的注册服务器镜像地址;
|
||||
* -s, --storage-driver="":指定使用给定的存储后端;
|
||||
* --selinux-enabled=true|false:是否启用 SELinux 支持。缺省值为 false。SELinux 目前尚不支持 overlay 存储驱动;
|
||||
* --storage-opt=[]:驱动后端选项;
|
||||
* --tls=true|false:是否对 Docker daemon 启用 TLS 安全机制,默认为否;
|
||||
* --tlscacert= /.docker/ca.pem:TLS CA 签名的可信证书文件路径;
|
||||
* --tlscert= /.docker/cert.pem:TLS 可信证书文件路径;
|
||||
* --tlscert= /.docker/key.pem:TLS 密钥文件路径;
|
||||
* --tlsverify=true|false:启用 TLS 校验,默认为否;
|
||||
* --userland-proxy=true|false:是否使用用户态代理来实现容器间和出容器的回环通信,默认为 true;
|
||||
* --userns-remap=default|uid:gid|user:group|user|uid:指定容器的用户命名空间,默认是创建新的 UID 和 GID 映射到容器内进程。
|
||||
|
||||
## 客户端命令
|
||||
|
||||
可以通过 `man docker-COMMAND` 或 `docker help COMMAND` 来查看这些命令的具体用法。
|
||||
|
||||
* attach:依附到一个正在运行的容器中;
|
||||
* build:从一个 Dockerfile 创建一个镜像;
|
||||
* commit:从一个容器的修改中创建一个新的镜像;
|
||||
* cp:在容器和本地宿主系统之间复制文件中;
|
||||
* create:创建一个新容器,但并不运行它;
|
||||
* diff:检查一个容器内文件系统的修改,包括修改和增加;
|
||||
* events:从服务端获取实时的事件;
|
||||
* exec:在运行的容器内执行命令;
|
||||
* export:导出容器内容为一个 tar 包;
|
||||
* history:显示一个镜像的历史信息;
|
||||
* images:列出存在的镜像;
|
||||
* import:导入一个文件(典型为 tar 包)路径或目录来创建一个本地镜像;
|
||||
* info:显示一些相关的系统信息;
|
||||
* inspect:显示一个容器的具体配置信息;
|
||||
* kill:关闭一个运行中的容器 (包括进程和所有相关资源);
|
||||
* load:从一个 tar 包中加载一个镜像;
|
||||
* login:注册或登录到一个 Docker 的仓库服务器;
|
||||
* logout:从 Docker 的仓库服务器登出;
|
||||
* logs:获取容器的 log 信息;
|
||||
* network:管理 Docker 的网络,包括查看、创建、删除、挂载、卸载等;
|
||||
* node:管理 swarm 集群中的节点,包括查看、更新、删除、提升/取消管理节点等;
|
||||
* pause:暂停一个容器中的所有进程;
|
||||
* port:查找一个 nat 到一个私有网口的公共口;
|
||||
* ps:列出主机上的容器;
|
||||
* pull:从一个Docker的仓库服务器下拉一个镜像或仓库;
|
||||
* push:将一个镜像或者仓库推送到一个 Docker 的注册服务器;
|
||||
* rename:重命名一个容器;
|
||||
* restart:重启一个运行中的容器;
|
||||
* rm:删除给定的若干个容器;
|
||||
* rmi:删除给定的若干个镜像;
|
||||
* run:创建一个新容器,并在其中运行给定命令;
|
||||
* save:保存一个镜像为 tar 包文件;
|
||||
* search:在 Docker index 中搜索一个镜像;
|
||||
* service:管理 Docker 所启动的应用服务,包括创建、更新、删除等;
|
||||
* start:启动一个容器;
|
||||
* stats:输出(一个或多个)容器的资源使用统计信息;
|
||||
* stop:终止一个运行中的容器;
|
||||
* swarm:管理 Docker swarm 集群,包括创建、加入、退出、更新等;
|
||||
* tag:为一个镜像打标签;
|
||||
* top:查看一个容器中的正在运行的进程信息;
|
||||
* unpause:将一个容器内所有的进程从暂停状态中恢复;
|
||||
* update:更新指定的若干容器的配置信息;
|
||||
* version:输出 Docker 的版本信息;
|
||||
* volume:管理 Docker volume,包括查看、创建、删除等;
|
||||
* wait:阻塞直到一个容器终止,然后输出它的退出符。
|
||||
|
||||
## 一张图总结 Docker 的命令
|
||||
![Docker 命令总结](../_images/cmd_logic.png)
|
187
appendix/faq/README.md
Normal file
187
appendix/faq/README.md
Normal file
@ -0,0 +1,187 @@
|
||||
# 常见问题总结
|
||||
|
||||
## 镜像相关
|
||||
### 如何批量清理临时镜像文件
|
||||
答:可以使用 `docker rmi $(docker images -q -f dangling=true)` 命令。
|
||||
|
||||
### 如何查看镜像支持的环境变量?
|
||||
答:可以使用 `docker run IMAGE env` 命令。
|
||||
|
||||
### 本地的镜像文件都存放在哪里?
|
||||
答:与 Docker 相关的本地资源都存放在 `/var/lib/docker/` 目录下,以 aufs 文件系统为例,其中 container 目录存放容器信息,graph 目录存放镜像信息,aufs 目录下存放具体的镜像层文件。
|
||||
|
||||
### 构建 Docker 镜像应该遵循哪些原则?
|
||||
答:整体原则上,尽量保持镜像功能的明确和内容的精简,要点包括
|
||||
|
||||
* 尽量选取满足需求但较小的基础系统镜像,例如大部分时候可以选择 debian:wheezy 或 debian:jessie 镜像,仅有不足百兆大小;
|
||||
* 清理编译生成文件、安装包的缓存等临时文件;
|
||||
* 安装各个软件时候要指定准确的版本号,并避免引入不需要的依赖;
|
||||
* 从安全角度考虑,应用要尽量使用系统的库和依赖;
|
||||
* 如果安装应用时候需要配置一些特殊的环境变量,在安装后要还原不需要保持的变量值;
|
||||
* 使用 Dockerfile 创建镜像时候要添加 .dockerignore 文件或使用干净的工作目录。
|
||||
|
||||
### 碰到网络问题,无法 pull 镜像,命令行指定 http_proxy 无效?
|
||||
答:在 Docker 配置文件中添加 `export http_proxy="http://<PROXY_HOST>:<PROXY_PORT>"`,之后重启 Docker 服务即可。
|
||||
|
||||
## 容器相关
|
||||
### 容器退出后,通过 docker ps 命令查看不到,数据会丢失么?
|
||||
答:容器退出后会处于终止(exited)状态,此时可以通过 `docker ps -a` 查看。其中的数据也不会丢失,还可以通过 `docker start` 命令来启动它。只有删除掉容器才会清除所有数据。
|
||||
|
||||
### 如何停止所有正在运行的容器
|
||||
答:可以使用 `docker kill $(docker ps -q)` 命令。
|
||||
|
||||
### 如何清理批量后台停止的容器?
|
||||
答:可以使用 `docker rm -f $(docker ps -qa)` 命令。
|
||||
|
||||
### 如何获取某个容器的 PID 信息?
|
||||
答:可以使用 `docker inspect --format '{{ .State.Pid }}' <CONTAINER ID or NAME>` 命令。
|
||||
|
||||
### 如何获取某个容器的 IP 地址?
|
||||
答:可以使用 `docker inspect --format '{{ .NetworkSettings.IPAddress }}' <CONTAINER ID or NAME>` 命令
|
||||
|
||||
### 如何给容器指定一个固定 IP 地址,而不是每次重启容器 IP 地址都会变?
|
||||
答:目前 Docker 并没有提供直接的对容器 IP 地址的管理支持,用户可以考虑参考第三部分中高级网络配置章节中介绍的创建点对点连接例子,来手动配置容器的静态 IP。或者在启动容器后,再手动进行修改(可参考其它类的问题 “*如何进入 Docker 容器的网络命名空间?*”)。
|
||||
|
||||
### 如何临时退出一个正在交互的容器的终端,而不终止它?
|
||||
答:按 `Ctrl-p Ctrl-q`。如果按 `Ctrl-c` 往往会让容器内应用进程终止,进而会终止容器。
|
||||
|
||||
### 使用 `docker port` 命令映射容器的端口时,系统报错“Error: No public port '80' published for xxx”?
|
||||
答:
|
||||
|
||||
* 创建镜像时 Dockerfile 要通过 EXPOSE 指定正确的开放端口;
|
||||
* 容器启动时指定 `PublishAllPort = true`。
|
||||
|
||||
### 可以在一个容器中同时运行多个应用进程么?
|
||||
答:一般并不推荐在同一个容器内运行多个应用进程。如果有类似需求,可以通过一些额外的进程管理机制,比如 supervisord 来管理所运行的进程。可以参考 https://docs.docker.com/articles/using_supervisord/。
|
||||
|
||||
### 如何控制容器占用系统资源(CPU、内存)的份额?
|
||||
答:在使用 `docker create` 命令创建容器或使用 `docker run` 创建并启动容器的时候,可以使用 -c|--cpu-shares[=0] 参数来调整容器使用 CPU 的权重;使用 -m|--memory[=MEMORY] 参数来调整容器使用内存的大小。
|
||||
|
||||
## 仓库相关
|
||||
### 仓库(Repository)、注册服务器(Registry)、注册索引(Index) 有何关系?
|
||||
首先,仓库是存放一组关联镜像的集合,比如同一个应用的不同版本的镜像。
|
||||
|
||||
注册服务器是存放实际的镜像文件的地方。注册索引则负责维护用户的账号、权限、搜索、标签等的管理。因此,注册服务器利用注册索引来实现认证等管理。
|
||||
|
||||
### 从非官方仓库(例如 non-official-repo.com)下载镜像时候,有时候会提示“Error: Invalid registry endpoint https://non-official-repo.com/v1/……”?
|
||||
答:Docker 自 1.3.0 版本往后,加强了对镜像安全性的验证,需要添加私有仓库证书,或者手动添加对非官方仓库的信任。
|
||||
编辑 Docker 配置文件,在其中添加:
|
||||
|
||||
```sh
|
||||
DOCKER_OPTS="--insecure-registry non-official-repo"
|
||||
```
|
||||
之后,重启 Docker 服务即可。
|
||||
|
||||
## 配置相关
|
||||
### Docker 的配置文件放在哪里,如何修改配置?
|
||||
答:使用 upstart 的系统(如Ubuntu 14.04)的配置文件在 `/etc/default/docker`,使用systemd 的系统(如 Ubuntu 16.04、Centos 等)的配置文件在 `/etc/systemd/system/docker.service.d/docker.conf`。
|
||||
|
||||
Ubuntu 下面的配置文件内容如下,读者可以参考配。(如果出现该文件不存在的情况,重启或者自己新建一个文件都可以解决。)
|
||||
|
||||
```sh
|
||||
# Customize location of Docker binary (especially for development testing).
|
||||
#DOCKERD="/usr/local/bin/dockerd"
|
||||
|
||||
# Use DOCKER_OPTS to modify the daemon startup options.
|
||||
#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
|
||||
|
||||
# If you need Docker to use an HTTP proxy, it can also be specified here.
|
||||
#export http_proxy="http://127.0.0.1:3128/"
|
||||
|
||||
# This is also a handy place to tweak where Docker's temporary files go.
|
||||
#export TMPDIR="/mnt/bigdrive/docker-tmp"
|
||||
```
|
||||
|
||||
### 如何更改 Docker 的默认存储位置?
|
||||
答:Docker 的默认存储位置是 `/var/lib/docker`,如果希望将 Docker 的本地文件存储到其他分区,可以使用 Linux 软连接的方式来完成,或者在启动 daemon 时通过 `-g` 参数指定。
|
||||
|
||||
例如,如下操作将默认存储位置迁移到 /storage/docker。
|
||||
|
||||
```sh
|
||||
[root@s26 ~]# df -h
|
||||
Filesystem Size Used Avail Use% Mounted on
|
||||
/dev/mapper/VolGroup-lv_root 50G 5.3G 42G 12% /
|
||||
tmpfs 48G 228K 48G 1% /dev/shm
|
||||
/dev/sda1 485M 40M 420M 9% /boot
|
||||
/dev/mapper/VolGroup-lv_home 222G 188M 210G 1% /home
|
||||
/dev/sdb2 2.7T 323G 2.3T 13% /storage
|
||||
[root@s26 ~]# service docker stop
|
||||
[root@s26 ~]# cd /var/lib/
|
||||
[root@s26 lib]# mv docker /storage/
|
||||
[root@s26 lib]# ln -s /storage/docker/ docker
|
||||
[root@s26 lib]# ls -la docker
|
||||
lrwxrwxrwx. 1 root root 15 11月 17 13:43 docker -> /storage/docker
|
||||
[root@s26 lib]# service docker start
|
||||
```
|
||||
|
||||
### 使用内存和 swap 限制启动容器时候报警告:“WARNING: Your kernel does not support cgroup swap limit. WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.”?
|
||||
答:这是因为系统默认没有开启对内存和 swap 使用的统计功能,引入该功能会带来性能的下降。要开启该功能,可以采取如下操作:
|
||||
|
||||
* 编辑 `/etc/default/grub` 文件(Ubuntu 系统为例),配置 `GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"`;
|
||||
* 更新 grub:`$ sudo update-grub`;
|
||||
* 重启系统,即可。
|
||||
|
||||
## Docker 与虚拟化
|
||||
|
||||
### Docker 与 LXC(Linux Container)有何不同?
|
||||
答:LXC 利用 Linux 上相关技术实现了容器。Docker 则在如下的几个方面进行了改进:
|
||||
* 移植性:通过抽象容器配置,容器可以实现从一个平台移植到另一个平台;
|
||||
* 镜像系统:基于 AUFS 的镜像系统为容器的分发带来了很多的便利,同时共同的镜像层只需要存储一份,实现高效率的存储;
|
||||
* 版本管理:类似于Git的版本管理理念,用户可以更方便的创建、管理镜像文件;
|
||||
* 仓库系统:仓库系统大大降低了镜像的分发和管理的成本;
|
||||
* 周边工具:各种现有工具(配置管理、云平台)对 Docker 的支持,以及基于 Docker的 PaaS、CI 等系统,让 Docker 的应用更加方便和多样化。
|
||||
|
||||
### Docker 与 Vagrant 有何不同?
|
||||
答:两者的定位完全不同。
|
||||
|
||||
* Vagrant 类似 Boot2Docker(一款运行 Docker 的最小内核),是一套虚拟机的管理环境。Vagrant 可以在多种系统上和虚拟机软件中运行,可以在 Windows,Mac 等非 Linux 平台上为 Docker 提供支持,自身具有较好的包装性和移植性。
|
||||
|
||||
* 原生的 Docker 自身只能运行在 Linux 平台上,但启动和运行的性能都比虚拟机要快,往往更适合快速开发和部署应用的场景。
|
||||
|
||||
简单说:Vagrant 适合用来管理虚拟机,而 Docker 适合用来管理应用环境。
|
||||
|
||||
### 开发环境中 Docker 和 Vagrant 该如何选择?
|
||||
答:
|
||||
Docker 不是虚拟机,而是进程隔离,对于资源的消耗很少,但是目前需要 Linux 环境支持。Vagrant 是虚拟机上做的封装,虚拟机本身会消耗资源。
|
||||
|
||||
如果本地使用的 Linux 环境,推荐都使用 Docker。
|
||||
|
||||
如果本地使用的是 OSX 或者 Windows 环境,那就需要开虚拟机,单一开发环境下 Vagrant 更简单;多环境开发下推荐在 Vagrant 里面再使用 Docker 进行环境隔离。
|
||||
|
||||
## 其它
|
||||
|
||||
### Docker 能在非 Linux 平台(比如 Windows 或 MacOS)上运行么?
|
||||
答:可以。目前需要使用 docker for mac、boot2docker 等软件创建一个轻量级的 Linux 虚拟机层。
|
||||
|
||||
### 如何将一台宿主主机的 docker 环境迁移到另外一台宿主主机
|
||||
答:停止 Docker 服务。将整个 Docker 存储文件夹复制到另外一台宿主主机,然后调整另外一台宿主主机的配置即可。
|
||||
|
||||
### 如何进入 Docker 容器的网络命名空间?
|
||||
答:Docker 在创建容器后,删除了宿主主机上 `/var/run/netns` 目录中的相关的网络命名空间文件。因此,在宿主主机上是无法看到或访问容器的网络命名空间的。
|
||||
|
||||
用户可以通过如下方法来手动恢复它。
|
||||
|
||||
首先,使用下面的命令查看容器进程信息,比如这里的1234。
|
||||
|
||||
```sh
|
||||
$ docker inspect --format='{{. State.Pid}} ' $container_id
|
||||
1234
|
||||
```
|
||||
接下来,在 /proc 目录下,把对应的网络命名空间文件链接到 /var/run/netns 目录。
|
||||
|
||||
```sh
|
||||
$ sudo ln -s /proc/1234/ns/net /var/run/netns/
|
||||
```
|
||||
|
||||
然后,在宿主主机上就可以看到容器的网络命名空间信息。例如
|
||||
|
||||
```sh
|
||||
$ sudo ip netns show
|
||||
1234
|
||||
```
|
||||
|
||||
此时,用户可以通过正常的系统命令来查看或操作容器的命名空间了。例如修改容器的 IP 地址信息为 `172.17.0.100/16`。
|
||||
|
||||
```sh
|
||||
$ sudo ip netns exec 1234 ifconfig eth0 172.17.0.100/16
|
||||
```
|
2
appendix/repo/README.md
Normal file
2
appendix/repo/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# 热门镜像介绍
|
||||
本章将介绍一些热门镜像的功能,使用方法和生成它们的 Dockerfile 等。包括 Ubuntu、CentOS、MySQL、MongoDB、Redis、Nginx、Wordpress、Node.js 等。
|
58
appendix/repo/centos.md
Normal file
58
appendix/repo/centos.md
Normal file
@ -0,0 +1,58 @@
|
||||
## [CentOS](https://hub.docker.com/_/centos/)
|
||||
|
||||
### 基本信息
|
||||
[CentOS](https://en.wikipedia.org/wiki/CentOS) 是流行的 Linux 发行版,其软件包大多跟 RedHat 系列保持一致。
|
||||
|
||||
该仓库位于 https://hub.docker.com/_/centos/,提供了 CentOS 从 5 ~ 7 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
默认会启动一个最小化的 CentOS 环境。
|
||||
|
||||
```sh
|
||||
$ docker run --name some-centos -i -t centos bash
|
||||
bash-4.2#
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
|
||||
#### CentOS 5 版本
|
||||
```
|
||||
FROM scratch
|
||||
MAINTAINER The CentOS Project <cloud-ops@centos.org>
|
||||
ADD c5-docker.tar.xz /
|
||||
LABEL name="CentOS Base Image" \
|
||||
vendor="CentOS" \
|
||||
license="GPLv2" \
|
||||
build-date="2016-03-31"
|
||||
|
||||
# Default command
|
||||
CMD ["/bin/bash"]
|
||||
```
|
||||
|
||||
#### CentOS 6 版本
|
||||
```
|
||||
FROM scratch
|
||||
MAINTAINER https://github.com/CentOS/sig-cloud-instance-images
|
||||
ADD centos-6-docker.tar.xz /
|
||||
|
||||
LABEL name="CentOS Base Image" \
|
||||
vendor="CentOS" \
|
||||
license="GPLv2" \
|
||||
build-date="20160729"
|
||||
|
||||
CMD ["/bin/bash"]
|
||||
```
|
||||
|
||||
#### CentOS 7 版本
|
||||
```
|
||||
FROM scratch
|
||||
MAINTAINER https://github.com/CentOS/sig-cloud-instance-images
|
||||
ADD centos-7-docker.tar.xz /
|
||||
|
||||
LABEL name="CentOS Base Image" \
|
||||
vendor="CentOS" \
|
||||
license="GPLv2" \
|
||||
build-date="20160729"
|
||||
|
||||
CMD ["/bin/bash"]
|
||||
```
|
263
appendix/repo/mongodb.md
Normal file
263
appendix/repo/mongodb.md
Normal file
@ -0,0 +1,263 @@
|
||||
## [MongoDB](https://hub.docker.com/_/mongo/)
|
||||
|
||||
### 基本信息
|
||||
[MongoDB](https://en.wikipedia.org/wiki/MongoDB) 是开源的 NoSQL 数据库实现。
|
||||
|
||||
该仓库位于 https://hub.docker.com/_/mongo/,提供了 MongoDB 2.x ~ 3.x 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
默认会在 `27017` 端口启动数据库。
|
||||
|
||||
```sh
|
||||
$ docker run --name some-mongo -d mongo
|
||||
```
|
||||
|
||||
使用其他应用连接到容器,可以用
|
||||
|
||||
```sh
|
||||
$ docker run --name some-app --link some-mongo:mongo -d application-that-uses-mongo
|
||||
```
|
||||
|
||||
或者通过 `mongo`
|
||||
|
||||
```sh
|
||||
$ docker run -it --link some-mongo:mongo --rm mongo sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
|
||||
#### 2.6 版本
|
||||
```
|
||||
FROM debian:wheezy
|
||||
|
||||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
||||
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
ca-certificates wget \
|
||||
numactl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# grab gosu for easy step-down from root
|
||||
ENV GOSU_VERSION 1.7
|
||||
RUN set -x \
|
||||
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
||||
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
|
||||
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
||||
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
||||
&& chmod +x /usr/local/bin/gosu \
|
||||
&& gosu nobody true
|
||||
|
||||
ENV MONGO_VERSION 2.6.12
|
||||
|
||||
RUN set -x \
|
||||
&& wget -O mongo.tgz "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$MONGO_VERSION.tgz" \
|
||||
&& wget -O mongo.tgz.sig "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$MONGO_VERSION.tgz.sig" \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys DFFA3DCF326E302C4787673A01C4E7FAAAB2461C \
|
||||
&& gpg --batch --verify mongo.tgz.sig mongo.tgz \
|
||||
&& rm -r "$GNUPGHOME" mongo.tgz.sig \
|
||||
&& tar -xvf mongo.tgz -C /usr/local --strip-components=1 \
|
||||
&& rm mongo.tgz
|
||||
|
||||
RUN mkdir -p /data/db /data/configdb \
|
||||
&& chown -R mongodb:mongodb /data/db /data/configdb
|
||||
VOLUME /data/db /data/configdb
|
||||
|
||||
COPY docker-entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
EXPOSE 27017
|
||||
CMD ["mongod"]
|
||||
```
|
||||
|
||||
#### 3.0 版本
|
||||
```
|
||||
FROM debian:wheezy
|
||||
|
||||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
||||
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
numactl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# grab gosu for easy step-down from root
|
||||
ENV GOSU_VERSION 1.7
|
||||
RUN set -x \
|
||||
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
|
||||
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
||||
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
|
||||
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
||||
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
||||
&& chmod +x /usr/local/bin/gosu \
|
||||
&& gosu nobody true \
|
||||
&& apt-get purge -y --auto-remove ca-certificates wget
|
||||
|
||||
# gpg: key 7F0CEB10: public key "Richard Kreuter <richard@10gen.com>" imported
|
||||
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 492EAFE8CD016A07919F1D2B9ECBEC467F0CEB10
|
||||
|
||||
ENV MONGO_MAJOR 3.0
|
||||
ENV MONGO_VERSION 3.0.12
|
||||
|
||||
RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/$MONGO_MAJOR main" > /etc/apt/sources.list.d/mongodb-org.list
|
||||
|
||||
RUN set -x \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y \
|
||||
mongodb-org=$MONGO_VERSION \
|
||||
mongodb-org-server=$MONGO_VERSION \
|
||||
mongodb-org-shell=$MONGO_VERSION \
|
||||
mongodb-org-mongos=$MONGO_VERSION \
|
||||
mongodb-org-tools=$MONGO_VERSION \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -rf /var/lib/mongodb \
|
||||
&& mv /etc/mongod.conf /etc/mongod.conf.orig
|
||||
|
||||
RUN mkdir -p /data/db /data/configdb \
|
||||
&& chown -R mongodb:mongodb /data/db /data/configdb
|
||||
VOLUME /data/db /data/configdb
|
||||
|
||||
COPY docker-entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
EXPOSE 27017
|
||||
CMD ["mongod"]
|
||||
```
|
||||
|
||||
#### 3.2 版本
|
||||
|
||||
```
|
||||
FROM debian:wheezy
|
||||
|
||||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
||||
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
numactl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# grab gosu for easy step-down from root
|
||||
ENV GOSU_VERSION 1.7
|
||||
RUN set -x \
|
||||
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
|
||||
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
||||
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
|
||||
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
||||
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
||||
&& chmod +x /usr/local/bin/gosu \
|
||||
&& gosu nobody true \
|
||||
&& apt-get purge -y --auto-remove ca-certificates wget
|
||||
|
||||
# pub 4096R/AAB2461C 2014-02-25 [expires: 2016-02-25]
|
||||
# Key fingerprint = DFFA 3DCF 326E 302C 4787 673A 01C4 E7FA AAB2 461C
|
||||
# uid MongoDB 2.6 Release Signing Key <packaging@mongodb.com>
|
||||
#
|
||||
# pub 4096R/EA312927 2015-10-09 [expires: 2017-10-08]
|
||||
# Key fingerprint = 42F3 E95A 2C4F 0827 9C49 60AD D68F A50F EA31 2927
|
||||
# uid MongoDB 3.2 Release Signing Key <packaging@mongodb.com>
|
||||
#
|
||||
ENV GPG_KEYS \
|
||||
DFFA3DCF326E302C4787673A01C4E7FAAAB2461C \
|
||||
42F3E95A2C4F08279C4960ADD68FA50FEA312927
|
||||
RUN set -ex \
|
||||
&& for key in $GPG_KEYS; do \
|
||||
apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
|
||||
done
|
||||
|
||||
ENV MONGO_MAJOR 3.2
|
||||
ENV MONGO_VERSION 3.2.8
|
||||
|
||||
RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/$MONGO_MAJOR main" > /etc/apt/sources.list.d/mongodb-org.list
|
||||
|
||||
RUN set -x \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y \
|
||||
mongodb-org=$MONGO_VERSION \
|
||||
mongodb-org-server=$MONGO_VERSION \
|
||||
mongodb-org-shell=$MONGO_VERSION \
|
||||
mongodb-org-mongos=$MONGO_VERSION \
|
||||
mongodb-org-tools=$MONGO_VERSION \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -rf /var/lib/mongodb \
|
||||
&& mv /etc/mongod.conf /etc/mongod.conf.orig
|
||||
|
||||
RUN mkdir -p /data/db /data/configdb \
|
||||
&& chown -R mongodb:mongodb /data/db /data/configdb
|
||||
VOLUME /data/db /data/configdb
|
||||
|
||||
COPY docker-entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
EXPOSE 27017
|
||||
CMD ["mongod"]
|
||||
```
|
||||
|
||||
#### 3.3 版本
|
||||
|
||||
```
|
||||
FROM debian:jessie
|
||||
|
||||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
||||
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
numactl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# grab gosu for easy step-down from root
|
||||
ENV GOSU_VERSION 1.7
|
||||
RUN set -x \
|
||||
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
|
||||
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
||||
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
|
||||
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
||||
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
||||
&& chmod +x /usr/local/bin/gosu \
|
||||
&& gosu nobody true \
|
||||
&& apt-get purge -y --auto-remove ca-certificates wget
|
||||
|
||||
# pub 4096R/A15703C6 2016-01-11 [expires: 2018-01-10]
|
||||
# Key fingerprint = 0C49 F373 0359 A145 1858 5931 BC71 1F9B A157 03C6
|
||||
# uid MongoDB 3.4 Release Signing Key <packaging@mongodb.com>
|
||||
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 0C49F3730359A14518585931BC711F9BA15703C6
|
||||
|
||||
ENV MONGO_MAJOR 3.3
|
||||
ENV MONGO_VERSION 3.3.10
|
||||
|
||||
RUN echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/$MONGO_MAJOR main" > /etc/apt/sources.list.d/mongodb-org.list
|
||||
|
||||
RUN set -x \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y \
|
||||
mongodb-org-unstable=$MONGO_VERSION \
|
||||
mongodb-org-unstable-server=$MONGO_VERSION \
|
||||
mongodb-org-unstable-shell=$MONGO_VERSION \
|
||||
mongodb-org-unstable-mongos=$MONGO_VERSION \
|
||||
mongodb-org-unstable-tools=$MONGO_VERSION \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -rf /var/lib/mongodb \
|
||||
&& mv /etc/mongod.conf /etc/mongod.conf.orig
|
||||
|
||||
RUN mkdir -p /data/db /data/configdb \
|
||||
&& chown -R mongodb:mongodb /data/db /data/configdb
|
||||
VOLUME /data/db /data/configdb
|
||||
|
||||
COPY docker-entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
EXPOSE 27017
|
||||
CMD ["mongod"]
|
||||
```
|
124
appendix/repo/mysql.md
Normal file
124
appendix/repo/mysql.md
Normal file
@ -0,0 +1,124 @@
|
||||
## [MySQL](https://hub.docker.com/_/mysql/)
|
||||
|
||||
### 基本信息
|
||||
[MySQL](https://en.wikipedia.org/wiki/MySQL) 是开源的关系数据库实现。
|
||||
|
||||
该仓库位于 https://hub.docker.com/_/mysql/,提供了 MySQL 各个版本的镜像,包括 5.6 系列、5.7 系列等。
|
||||
|
||||
### 使用方法
|
||||
默认会在 `3306` 端口启动数据库。
|
||||
|
||||
```
|
||||
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
|
||||
```
|
||||
之后就可以使用其它应用来连接到该容器。
|
||||
|
||||
```
|
||||
$ docker run --name some-app --link some-mysql:mysql -d application-that-uses-mysql
|
||||
```
|
||||
或者通过 `mysql`。
|
||||
|
||||
```
|
||||
$ docker run -it --link some-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
#### 5.6 版本
|
||||
```
|
||||
FROM debian:wheezy
|
||||
|
||||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
||||
RUN groupadd -r mysql && useradd -r -g mysql mysql
|
||||
|
||||
# FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
|
||||
# File::Basename
|
||||
# File::Copy
|
||||
# Sys::Hostname
|
||||
# Data::Dumper
|
||||
RUN apt-get update && apt-get install -y perl --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
|
||||
RUN apt-get update && apt-get install -y libaio1 && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# gpg: key 5072E1F5: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
|
||||
RUN gpg --keyserver pgp.mit.edu --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5
|
||||
|
||||
ENV MYSQL_MAJOR 5.6
|
||||
ENV MYSQL_VERSION 5.6.20
|
||||
|
||||
# note: we're pulling the *.asc file from mysql.he.net instead of dev.mysql.com because the official mirror 404s that file for whatever reason - maybe it's at a different path?
|
||||
RUN apt-get update && apt-get install -y curl --no-install-recommends && rm -rf /var/lib/apt/lists/* \
|
||||
&& curl -SL "http://dev.mysql.com/get/Downloads/MySQL-$MYSQL_MAJOR/mysql-$MYSQL_VERSION-linux-glibc2.5-x86_64.tar.gz" -o mysql.tar.gz \
|
||||
&& curl -SL "http://mysql.he.net/Downloads/MySQL-$MYSQL_MAJOR/mysql-$MYSQL_VERSION-linux-glibc2.5-x86_64.tar.gz.asc" -o mysql.tar.gz.asc \
|
||||
&& apt-get purge -y --auto-remove curl \
|
||||
&& gpg --verify mysql.tar.gz.asc \
|
||||
&& mkdir /usr/local/mysql \
|
||||
&& tar -xzf mysql.tar.gz -C /usr/local/mysql --strip-components=1 \
|
||||
&& rm mysql.tar.gz* \
|
||||
&& rm -rf /usr/local/mysql/mysql-test /usr/local/mysql/sql-bench \
|
||||
&& rm -rf /usr/local/mysql/bin/*-debug /usr/local/mysql/bin/*_embedded \
|
||||
&& find /usr/local/mysql -type f -name "*.a" -delete \
|
||||
&& apt-get update && apt-get install -y binutils && rm -rf /var/lib/apt/lists/* \
|
||||
&& { find /usr/local/mysql -type f -executable -exec strip --strip-all '{}' + || true; } \
|
||||
&& apt-get purge -y --auto-remove binutils
|
||||
ENV PATH $PATH:/usr/local/mysql/bin:/usr/local/mysql/scripts
|
||||
|
||||
WORKDIR /usr/local/mysql
|
||||
VOLUME /var/lib/mysql
|
||||
|
||||
COPY docker-entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
EXPOSE 3306
|
||||
CMD ["mysqld", "--datadir=/var/lib/mysql", "--user=mysql"]
|
||||
```
|
||||
|
||||
#### 5.7 版本
|
||||
```
|
||||
FROM debian:wheezy
|
||||
|
||||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
||||
RUN groupadd -r mysql && useradd -r -g mysql mysql
|
||||
|
||||
# FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
|
||||
# File::Basename
|
||||
# File::Copy
|
||||
# Sys::Hostname
|
||||
# Data::Dumper
|
||||
RUN apt-get update && apt-get install -y perl --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
|
||||
RUN apt-get update && apt-get install -y libaio1 && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# gpg: key 5072E1F5: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
|
||||
RUN gpg --keyserver pgp.mit.edu --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5
|
||||
|
||||
ENV MYSQL_MAJOR 5.7
|
||||
ENV MYSQL_VERSION 5.7.4-m14
|
||||
|
||||
# note: we're pulling the *.asc file from mysql.he.net instead of dev.mysql.com because the official mirror 404s that file for whatever reason - maybe it's at a different path?
|
||||
RUN apt-get update && apt-get install -y curl --no-install-recommends && rm -rf /var/lib/apt/lists/* \
|
||||
&& curl -SL "http://dev.mysql.com/get/Downloads/MySQL-$MYSQL_MAJOR/mysql-$MYSQL_VERSION-linux-glibc2.5-x86_64.tar.gz" -o mysql.tar.gz \
|
||||
&& curl -SL "http://mysql.he.net/Downloads/MySQL-$MYSQL_MAJOR/mysql-$MYSQL_VERSION-linux-glibc2.5-x86_64.tar.gz.asc" -o mysql.tar.gz.asc \
|
||||
&& apt-get purge -y --auto-remove curl \
|
||||
&& gpg --verify mysql.tar.gz.asc \
|
||||
&& mkdir /usr/local/mysql \
|
||||
&& tar -xzf mysql.tar.gz -C /usr/local/mysql --strip-components=1 \
|
||||
&& rm mysql.tar.gz* \
|
||||
&& rm -rf /usr/local/mysql/mysql-test /usr/local/mysql/sql-bench \
|
||||
&& rm -rf /usr/local/mysql/bin/*-debug /usr/local/mysql/bin/*_embedded \
|
||||
&& find /usr/local/mysql -type f -name "*.a" -delete \
|
||||
&& apt-get update && apt-get install -y binutils && rm -rf /var/lib/apt/lists/* \
|
||||
&& { find /usr/local/mysql -type f -executable -exec strip --strip-all '{}' + || true; } \
|
||||
&& apt-get purge -y --auto-remove binutils
|
||||
ENV PATH $PATH:/usr/local/mysql/bin:/usr/local/mysql/scripts
|
||||
|
||||
WORKDIR /usr/local/mysql
|
||||
VOLUME /var/lib/mysql
|
||||
|
||||
COPY docker-entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
EXPOSE 3306
|
||||
CMD ["mysqld", "--datadir=/var/lib/mysql", "--user=mysql"]
|
||||
```
|
101
appendix/repo/nginx.md
Normal file
101
appendix/repo/nginx.md
Normal file
@ -0,0 +1,101 @@
|
||||
## [Nginx](https://hub.docker.com/_/nginx/)
|
||||
|
||||
### 基本信息
|
||||
[Nginx](https://en.wikipedia.org/wiki/Nginx) 是开源的高效的 Web 服务器实现,支持 HTTP、HTTPS、SMTP、POP3、IMAP 等协议。
|
||||
|
||||
该仓库位于 https://hub.docker.com/_/nginx/,提供了 Nginx 1.0 ~ 1.11.x 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
下面的命令将作为一个静态页面服务器启动。
|
||||
|
||||
```
|
||||
$ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx
|
||||
```
|
||||
用户也可以不使用这种映射方式,通过利用 Dockerfile 来直接将静态页面内容放到镜像中,内容为
|
||||
|
||||
```
|
||||
FROM nginx
|
||||
COPY static-html-directory /usr/share/nginx/html
|
||||
```
|
||||
之后生成新的镜像,并启动一个容器。
|
||||
|
||||
```
|
||||
$ docker build -t some-content-nginx .
|
||||
$ docker run --name some-nginx -d some-content-nginx
|
||||
```
|
||||
开放端口,并映射到本地的 `8080` 端口。
|
||||
|
||||
```
|
||||
docker run --name some-nginx -d -p 8080:80 some-content-nginx
|
||||
```
|
||||
|
||||
Nginx的默认配置文件路径为 `/etc/nginx/nginx.conf`,可以通过映射它来使用本地的配置文件,例如
|
||||
|
||||
```
|
||||
docker run --name some-nginx -v /some/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
|
||||
```
|
||||
使用配置文件时,为了在容器中正常运行,需要保持 `daemon off;`。
|
||||
|
||||
### Dockerfile
|
||||
#### stable 版本
|
||||
```
|
||||
FROM debian:jessie
|
||||
|
||||
MAINTAINER NGINX Docker Maintainers "docker-maint@nginx.com"
|
||||
|
||||
ENV NGINX_VERSION 1.10.1-1~jessie
|
||||
|
||||
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \
|
||||
&& echo "deb http://nginx.org/packages/debian/ jessie nginx" >> /etc/apt/sources.list \
|
||||
&& apt-get update \
|
||||
&& apt-get install --no-install-recommends --no-install-suggests -y \
|
||||
ca-certificates \
|
||||
nginx=${NGINX_VERSION} \
|
||||
nginx-module-xslt \
|
||||
nginx-module-geoip \
|
||||
nginx-module-image-filter \
|
||||
nginx-module-perl \
|
||||
nginx-module-njs \
|
||||
gettext-base \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# forward request and error logs to docker log collector
|
||||
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
|
||||
&& ln -sf /dev/stderr /var/log/nginx/error.log
|
||||
|
||||
EXPOSE 80 443
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
```
|
||||
|
||||
#### 1.11.x 版本
|
||||
|
||||
```
|
||||
FROM debian:jessie
|
||||
|
||||
MAINTAINER NGINX Docker Maintainers "docker-maint@nginx.com"
|
||||
|
||||
ENV NGINX_VERSION 1.11.1-1~jessie
|
||||
|
||||
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \
|
||||
&& echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list \
|
||||
&& apt-get update \
|
||||
&& apt-get install --no-install-recommends --no-install-suggests -y \
|
||||
ca-certificates \
|
||||
nginx=${NGINX_VERSION} \
|
||||
nginx-module-xslt \
|
||||
nginx-module-geoip \
|
||||
nginx-module-image-filter \
|
||||
nginx-module-perl \
|
||||
nginx-module-njs \
|
||||
gettext-base \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# forward request and error logs to docker log collector
|
||||
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
|
||||
&& ln -sf /dev/stderr /var/log/nginx/error.log
|
||||
|
||||
EXPOSE 80 443
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
```
|
151
appendix/repo/nodejs.md
Normal file
151
appendix/repo/nodejs.md
Normal file
@ -0,0 +1,151 @@
|
||||
## [Node.js](https://hub.docker.com/_/node/)
|
||||
|
||||
### 基本信息
|
||||
[Node.js](https://en.wikipedia.org/wiki/Node.js)是基于 JavaScript 的可扩展服务端和网络软件开发平台。
|
||||
|
||||
该仓库位于 https://hub.docker.com/_/node/,提供了 Node.js 0.10 ~ 6.3.x 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
在项目中创建一个 Dockerfile。
|
||||
|
||||
```
|
||||
FROM node:0.10-onbuild
|
||||
# replace this with your application's default port
|
||||
EXPOSE 8888
|
||||
```
|
||||
然后创建镜像,并启动容器。
|
||||
|
||||
```
|
||||
$ docker build -t my-nodejs-app
|
||||
$ docker run -it --rm --name my-running-app my-nodejs-app
|
||||
```
|
||||
|
||||
也可以直接运行一个简单容器。
|
||||
|
||||
```
|
||||
$ docker run -it --rm --name my-running-script -v "$(pwd)":/usr/src/myapp -w /usr/src/myapp node:0.10 node your-daemon-or-script.js
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
|
||||
#### 0.10 版本
|
||||
```
|
||||
FROM buildpack-deps
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
ca-certificates \
|
||||
curl
|
||||
|
||||
# verify gpg and sha256: http://nodejs.org/dist/v0.10.31/SHASUMS256.txt.asc
|
||||
# gpg: aka "Timothy J Fontaine (Work) <tj.fontaine@joyent.com>"
|
||||
RUN gpg --keyserver pgp.mit.edu --recv-keys 7937DFD2AB06298B2293C3187D33FF9D0246406D
|
||||
|
||||
ENV NODE_VERSION 0.10.32
|
||||
|
||||
RUN curl -SLO "http://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz" \
|
||||
&& curl -SLO "http://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
|
||||
&& gpg --verify SHASUMS256.txt.asc \
|
||||
&& grep " node-v$NODE_VERSION-linux-x64.tar.gz\$" SHASUMS256.txt.asc | sha256sum -c - \
|
||||
&& tar -xzf "node-v$NODE_VERSION-linux-x64.tar.gz" -C /usr/local --strip-components=1 \
|
||||
&& rm "node-v$NODE_VERSION-linux-x64.tar.gz" SHASUMS256.txt.asc
|
||||
|
||||
CMD [ "node" ]
|
||||
```
|
||||
|
||||
#### 4.x 版本
|
||||
```
|
||||
FROM buildpack-deps:jessie
|
||||
|
||||
# gpg keys listed at https://github.com/nodejs/node
|
||||
RUN set -ex \
|
||||
&& for key in \
|
||||
9554F04D7259F04124DE6B476D5A82AC7E37093B \
|
||||
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
|
||||
0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
|
||||
FD3A5288F042B6850C66B31F09FE44734EB7990E \
|
||||
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
|
||||
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
|
||||
B9AE9905FFD7803F25714661B63B535A4C206CA9 \
|
||||
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
|
||||
; do \
|
||||
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
|
||||
done
|
||||
|
||||
ENV NPM_CONFIG_LOGLEVEL info
|
||||
ENV NODE_VERSION 4.4.7
|
||||
|
||||
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
|
||||
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
|
||||
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
|
||||
&& grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
|
||||
&& tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
|
||||
&& rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt
|
||||
|
||||
CMD [ "node" ]
|
||||
```
|
||||
|
||||
#### 5.x 版本
|
||||
|
||||
```
|
||||
FROM buildpack-deps:jessie
|
||||
|
||||
# gpg keys listed at https://github.com/nodejs/node
|
||||
RUN set -ex \
|
||||
&& for key in \
|
||||
9554F04D7259F04124DE6B476D5A82AC7E37093B \
|
||||
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
|
||||
0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
|
||||
FD3A5288F042B6850C66B31F09FE44734EB7990E \
|
||||
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
|
||||
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
|
||||
B9AE9905FFD7803F25714661B63B535A4C206CA9 \
|
||||
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
|
||||
; do \
|
||||
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
|
||||
done
|
||||
|
||||
ENV NPM_CONFIG_LOGLEVEL info
|
||||
ENV NODE_VERSION 5.12.0
|
||||
|
||||
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
|
||||
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
|
||||
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
|
||||
&& grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
|
||||
&& tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
|
||||
&& rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt
|
||||
|
||||
CMD [ "node" ]
|
||||
```
|
||||
|
||||
#### 6.x 版本
|
||||
```
|
||||
FROM buildpack-deps:jessie
|
||||
|
||||
# gpg keys listed at https://github.com/nodejs/node
|
||||
RUN set -ex \
|
||||
&& for key in \
|
||||
9554F04D7259F04124DE6B476D5A82AC7E37093B \
|
||||
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
|
||||
0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
|
||||
FD3A5288F042B6850C66B31F09FE44734EB7990E \
|
||||
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
|
||||
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
|
||||
B9AE9905FFD7803F25714661B63B535A4C206CA9 \
|
||||
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
|
||||
; do \
|
||||
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
|
||||
done
|
||||
|
||||
ENV NPM_CONFIG_LOGLEVEL info
|
||||
ENV NODE_VERSION 6.3.1
|
||||
|
||||
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
|
||||
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
|
||||
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
|
||||
&& grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
|
||||
&& tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
|
||||
&& rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt
|
||||
|
||||
CMD [ "node" ]
|
||||
```
|
||||
|
141
appendix/repo/redis.md
Normal file
141
appendix/repo/redis.md
Normal file
@ -0,0 +1,141 @@
|
||||
## [Redis](https://hub.docker.com/_/redis/)
|
||||
|
||||
### 基本信息
|
||||
[Redis](https://en.wikipedia.org/wiki/Redis) 是开源的内存 Key-Value 数据库实现。
|
||||
|
||||
该仓库位于 https://hub.docker.com/_/redis/,提供了 Redis 3.x 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
默认会在 `6379` 端口启动数据库。
|
||||
|
||||
```
|
||||
$ docker run --name some-redis -d redis
|
||||
```
|
||||
另外还可以启用 [持久存储](http://redis.io/topics/persistence)。
|
||||
|
||||
```
|
||||
$ docker run --name some-redis -d redis redis-server --appendonly yes
|
||||
```
|
||||
|
||||
默认数据存储位置在 `VOLUME/data`。可以使用 `--volumes-from some-volume-container` 或 `-v /docker/host/dir:/data` 将数据存放到本地。
|
||||
|
||||
使用其他应用连接到容器,可以用
|
||||
|
||||
```
|
||||
$ docker run --name some-app --link some-redis:redis -d application-that-uses-redis
|
||||
```
|
||||
或者通过 `redis-cli`
|
||||
|
||||
```
|
||||
$ docker run -it --link some-redis:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
#### 3.0 版本
|
||||
```
|
||||
FROM debian:jessie
|
||||
|
||||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
||||
RUN groupadd -r redis && useradd -r -g redis redis
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
wget \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# grab gosu for easy step-down from root
|
||||
ENV GOSU_VERSION 1.7
|
||||
RUN set -x \
|
||||
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
||||
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
|
||||
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
||||
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
||||
&& chmod +x /usr/local/bin/gosu \
|
||||
&& gosu nobody true
|
||||
|
||||
ENV REDIS_VERSION 3.0.7
|
||||
ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-3.0.7.tar.gz
|
||||
ENV REDIS_DOWNLOAD_SHA1 e56b4b7e033ae8dbf311f9191cf6fdf3ae974d1c
|
||||
|
||||
# for redis-sentinel see: http://redis.io/topics/sentinel
|
||||
RUN buildDeps='gcc libc6-dev make' \
|
||||
&& set -x \
|
||||
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL" \
|
||||
&& echo "$REDIS_DOWNLOAD_SHA1 *redis.tar.gz" | sha1sum -c - \
|
||||
&& mkdir -p /usr/src/redis \
|
||||
&& tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \
|
||||
&& rm redis.tar.gz \
|
||||
&& make -C /usr/src/redis \
|
||||
&& make -C /usr/src/redis install \
|
||||
&& rm -r /usr/src/redis \
|
||||
&& apt-get purge -y --auto-remove $buildDeps
|
||||
|
||||
RUN mkdir /data && chown redis:redis /data
|
||||
VOLUME /data
|
||||
WORKDIR /data
|
||||
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
|
||||
EXPOSE 6379
|
||||
CMD [ "redis-server" ]
|
||||
```
|
||||
|
||||
#### 3.2 版本
|
||||
```
|
||||
FROM debian:jessie
|
||||
|
||||
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
||||
RUN groupadd -r redis && useradd -r -g redis redis
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
wget \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# grab gosu for easy step-down from root
|
||||
ENV GOSU_VERSION 1.7
|
||||
RUN set -x \
|
||||
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
||||
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
||||
&& export GNUPGHOME="$(mktemp -d)" \
|
||||
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
|
||||
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
||||
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
||||
&& chmod +x /usr/local/bin/gosu \
|
||||
&& gosu nobody true
|
||||
|
||||
ENV REDIS_VERSION 3.2.3
|
||||
ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-3.2.3.tar.gz
|
||||
ENV REDIS_DOWNLOAD_SHA1 92d6d93ef2efc91e595c8bf578bf72baff397507
|
||||
|
||||
# for redis-sentinel see: http://redis.io/topics/sentinel
|
||||
RUN buildDeps='gcc libc6-dev make' \
|
||||
&& set -x \
|
||||
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL" \
|
||||
&& echo "$REDIS_DOWNLOAD_SHA1 *redis.tar.gz" | sha1sum -c - \
|
||||
&& mkdir -p /usr/src/redis \
|
||||
&& tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \
|
||||
&& rm redis.tar.gz \
|
||||
&& make -C /usr/src/redis \
|
||||
&& make -C /usr/src/redis install \
|
||||
&& rm -r /usr/src/redis \
|
||||
&& apt-get purge -y --auto-remove $buildDeps
|
||||
|
||||
RUN mkdir /data && chown redis:redis /data
|
||||
VOLUME /data
|
||||
WORKDIR /data
|
||||
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
|
||||
EXPOSE 6379
|
||||
CMD [ "redis-server" ]
|
||||
```
|
142
appendix/repo/ubuntu.md
Normal file
142
appendix/repo/ubuntu.md
Normal file
@ -0,0 +1,142 @@
|
||||
## [Ubuntu](https://hub.docker.com/_/ubuntu/)
|
||||
|
||||
### 基本信息
|
||||
[Ubuntu](https://en.wikipedia.org/wiki/Ubuntu) 是流行的 Linux 发行版,其自带软件版本往往较新一些。
|
||||
|
||||
该仓库位于 https://hub.docker.com/_/ubuntu/,提供了 Ubuntu 从 12.04 ~ 16.10 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
默认会启动一个最小化的 Ubuntu 环境。
|
||||
|
||||
```
|
||||
$ docker run --name some-ubuntu -i -t ubuntu
|
||||
root@523c70904d54:/#
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
|
||||
#### 12.04 版本
|
||||
```
|
||||
FROM scratch
|
||||
ADD precise-core-amd64.tar.gz /
|
||||
|
||||
# a few minor docker-specific tweaks
|
||||
# see https://github.com/dotcloud/docker/blob/master/contrib/mkimage/debootstrap
|
||||
RUN echo '#!/bin/sh' > /usr/sbin/policy-rc.d \
|
||||
&& echo 'exit 101' >> /usr/sbin/policy-rc.d \
|
||||
&& chmod +x /usr/sbin/policy-rc.d \
|
||||
\
|
||||
&& dpkg-divert --local --rename --add /sbin/initctl \
|
||||
&& cp -a /usr/sbin/policy-rc.d /sbin/initctl \
|
||||
&& sed -i 's/^exit.*/exit 0/' /sbin/initctl \
|
||||
\
|
||||
&& echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \
|
||||
\
|
||||
&& echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \
|
||||
&& echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \
|
||||
&& echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \
|
||||
\
|
||||
&& echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \
|
||||
\
|
||||
&& echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes
|
||||
|
||||
# delete all the apt list files since they're big and get stale quickly
|
||||
RUN rm -rf /var/lib/apt/lists/*
|
||||
# this forces "apt-get update" in dependent images, which is also good
|
||||
|
||||
# enable the universe
|
||||
RUN sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list
|
||||
|
||||
# upgrade packages for now, since the tarballs aren't updated frequently enough
|
||||
RUN apt-get update && apt-get dist-upgrade -y && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# overwrite this with 'CMD []' in a dependent Dockerfile
|
||||
CMD ["/bin/bash"]
|
||||
```
|
||||
|
||||
#### 14.04 版本
|
||||
```
|
||||
FROM scratch
|
||||
ADD trusty-core-amd64.tar.gz /
|
||||
|
||||
# a few minor docker-specific tweaks
|
||||
# see https://github.com/dotcloud/docker/blob/master/contrib/mkimage/debootstrap
|
||||
RUN echo '#!/bin/sh' > /usr/sbin/policy-rc.d \
|
||||
&& echo 'exit 101' >> /usr/sbin/policy-rc.d \
|
||||
&& chmod +x /usr/sbin/policy-rc.d \
|
||||
\
|
||||
&& dpkg-divert --local --rename --add /sbin/initctl \
|
||||
&& cp -a /usr/sbin/policy-rc.d /sbin/initctl \
|
||||
&& sed -i 's/^exit.*/exit 0/' /sbin/initctl \
|
||||
\
|
||||
&& echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \
|
||||
\
|
||||
&& echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \
|
||||
&& echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \
|
||||
&& echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \
|
||||
\
|
||||
&& echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \
|
||||
\
|
||||
&& echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes
|
||||
|
||||
# delete all the apt list files since they're big and get stale quickly
|
||||
RUN rm -rf /var/lib/apt/lists/*
|
||||
# this forces "apt-get update" in dependent images, which is also good
|
||||
|
||||
# enable the universe
|
||||
RUN sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list
|
||||
|
||||
# upgrade packages for now, since the tarballs aren't updated frequently enough
|
||||
RUN apt-get update && apt-get dist-upgrade -y && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# overwrite this with 'CMD []' in a dependent Dockerfile
|
||||
CMD ["/bin/bash"]
|
||||
```
|
||||
|
||||
#### 16.04 版本
|
||||
|
||||
```
|
||||
FROM scratch
|
||||
ADD ubuntu-xenial-core-cloudimg-amd64-root.tar.gz /
|
||||
|
||||
# a few minor docker-specific tweaks
|
||||
# see https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap
|
||||
RUN set -xe \
|
||||
\
|
||||
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L40-L48
|
||||
&& echo '#!/bin/sh' > /usr/sbin/policy-rc.d \
|
||||
&& echo 'exit 101' >> /usr/sbin/policy-rc.d \
|
||||
&& chmod +x /usr/sbin/policy-rc.d \
|
||||
\
|
||||
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L54-L56
|
||||
&& dpkg-divert --local --rename --add /sbin/initctl \
|
||||
&& cp -a /usr/sbin/policy-rc.d /sbin/initctl \
|
||||
&& sed -i 's/^exit.*/exit 0/' /sbin/initctl \
|
||||
\
|
||||
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L71-L78
|
||||
&& echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \
|
||||
\
|
||||
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L85-L105
|
||||
&& echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \
|
||||
&& echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \
|
||||
&& echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \
|
||||
\
|
||||
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L109-L115
|
||||
&& echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \
|
||||
\
|
||||
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L118-L130
|
||||
&& echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes \
|
||||
\
|
||||
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L134-L151
|
||||
&& echo 'Apt::AutoRemove::SuggestsImportant "false";' > /etc/apt/apt.conf.d/docker-autoremove-suggests
|
||||
|
||||
# delete all the apt list files since they're big and get stale quickly
|
||||
RUN rm -rf /var/lib/apt/lists/*
|
||||
# this forces "apt-get update" in dependent images, which is also good
|
||||
|
||||
# enable the universe
|
||||
RUN sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list
|
||||
|
||||
# overwrite this with 'CMD []' in a dependent Dockerfile
|
||||
CMD ["/bin/bash"]
|
||||
```
|
117
appendix/repo/wordpress.md
Normal file
117
appendix/repo/wordpress.md
Normal file
@ -0,0 +1,117 @@
|
||||
## [WordPress](https://hub.docker.com/_/wordpress/)
|
||||
|
||||
### 基本信息
|
||||
[WordPress](https://en.wikipedia.org/wiki/WordPress) 是开源的 Blog 和内容管理系统框架,它基于 PhP 和 MySQL。
|
||||
|
||||
该仓库位于 https://hub.docker.com/_/wordpress/,提供了 WordPress 4.x 版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
启动容器需要 MySQL 的支持,默认端口为 `80`。
|
||||
|
||||
```
|
||||
$ docker run --name some-wordpress --link some-mysql:mysql -d wordpress
|
||||
```
|
||||
启动 WordPress 容器时可以指定的一些环境参数包括:
|
||||
|
||||
* `-e WORDPRESS_DB_USER=...` 缺省为 “root”
|
||||
* `-e WORDPRESS_DB_PASSWORD=...` 缺省为连接 mysql 容器的环境变量 `MYSQL_ROOT_PASSWORD` 的值
|
||||
* `-e WORDPRESS_DB_NAME=...` 缺省为 “wordpress”
|
||||
* `-e WORDPRESS_AUTH_KEY=...`, `-e WORDPRESS_SECURE_AUTH_KEY=...`, `-e WORDPRESS_LOGGED_IN_KEY=...`, `-e WORDPRESS_NONCE_KEY=...`, `-e WORDPRESS_AUTH_SALT=...`, `-e WORDPRESS_SECURE_AUTH_SALT=...`, `-e WORDPRESS_LOGGED_IN_SALT=...`, `-e WORDPRESS_NONCE_SALT=...` 缺省为随机 sha1 串
|
||||
|
||||
### Dockerfile
|
||||
#### 4.0 版本
|
||||
```
|
||||
FROM debian:wheezy
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
apache2 \
|
||||
curl \
|
||||
libapache2-mod-php5 \
|
||||
php5-curl \
|
||||
php5-gd \
|
||||
php5-mysql \
|
||||
rsync \
|
||||
wget \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
RUN a2enmod rewrite
|
||||
|
||||
# copy a few things from apache's init script that it requires to be setup
|
||||
ENV APACHE_CONFDIR /etc/apache2
|
||||
ENV APACHE_ENVVARS $APACHE_CONFDIR/envvars
|
||||
# and then a few more from $APACHE_CONFDIR/envvars itself
|
||||
ENV APACHE_RUN_USER www-data
|
||||
ENV APACHE_RUN_GROUP www-data
|
||||
ENV APACHE_RUN_DIR /var/run/apache2
|
||||
ENV APACHE_PID_FILE $APACHE_RUN_DIR/apache2.pid
|
||||
ENV APACHE_LOCK_DIR /var/lock/apache2
|
||||
ENV APACHE_LOG_DIR /var/log/apache2
|
||||
ENV LANG C
|
||||
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
|
||||
|
||||
# make CustomLog (access log) go to stdout instead of files
|
||||
# and ErrorLog to stderr
|
||||
RUN find "$APACHE_CONFDIR" -type f -exec sed -ri ' \
|
||||
s!^(\s*CustomLog)\s+\S+!\1 /proc/self/fd/1!g; \
|
||||
s!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g; \
|
||||
' '{}' ';'
|
||||
|
||||
RUN rm -rf /var/www/html && mkdir /var/www/html
|
||||
VOLUME /var/www/html
|
||||
WORKDIR /var/www/html
|
||||
|
||||
ENV WORDPRESS_VERSION 4.0.0
|
||||
ENV WORDPRESS_UPSTREAM_VERSION 4.0
|
||||
|
||||
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
||||
RUN curl -SL http://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz | tar -xzC /usr/src/
|
||||
|
||||
COPY docker-apache.conf /etc/apache2/sites-available/wordpress
|
||||
RUN a2dissite 000-default && a2ensite wordpress
|
||||
|
||||
COPY docker-entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
EXPOSE 80
|
||||
CMD ["apache2", "-DFOREGROUND"]
|
||||
```
|
||||
|
||||
#### 4.5 版本
|
||||
```
|
||||
FROM php:5.6-apache
|
||||
|
||||
RUN a2enmod rewrite expires
|
||||
|
||||
# install the PHP extensions we need
|
||||
RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev && rm -rf /var/lib/apt/lists/* \
|
||||
&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
|
||||
&& docker-php-ext-install gd mysqli opcache
|
||||
|
||||
# set recommended PHP.ini settings
|
||||
# see https://secure.php.net/manual/en/opcache.installation.php
|
||||
RUN { \
|
||||
echo 'opcache.memory_consumption=128'; \
|
||||
echo 'opcache.interned_strings_buffer=8'; \
|
||||
echo 'opcache.max_accelerated_files=4000'; \
|
||||
echo 'opcache.revalidate_freq=60'; \
|
||||
echo 'opcache.fast_shutdown=1'; \
|
||||
echo 'opcache.enable_cli=1'; \
|
||||
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
|
||||
|
||||
VOLUME /var/www/html
|
||||
|
||||
ENV WORDPRESS_VERSION 4.5.3
|
||||
ENV WORDPRESS_SHA1 835b68748dae5a9d31c059313cd0150f03a49269
|
||||
|
||||
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
||||
RUN curl -o wordpress.tar.gz -SL https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz \
|
||||
&& echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
|
||||
&& tar -xzf wordpress.tar.gz -C /usr/src/ \
|
||||
&& rm wordpress.tar.gz \
|
||||
&& chown -R www-data:www-data /usr/src/wordpress
|
||||
|
||||
COPY docker-entrypoint.sh /entrypoint.sh
|
||||
|
||||
# grr, ENTRYPOINT resets CMD now
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD ["apache2-foreground"]
|
||||
```
|
23
appendix/resources/README.md
Normal file
23
appendix/resources/README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# 资源链接
|
||||
|
||||
## 官方网站
|
||||
* Docker 官方主页: https://www.docker.com
|
||||
* Docker 官方博客: https://blog.docker.com/
|
||||
* Docker 官方文档: https://docs.docker.com/
|
||||
* Docker Hub: https://hub.docker.com
|
||||
* Docker 的源代码仓库: https://github.com/docker/docker
|
||||
* Docker 发布版本历史:https://docs.docker.com/release-notes/
|
||||
* Docker 常见问题:https://docs.docker.com/engine/faq/
|
||||
* Docker 远端应用 API: https://docs.docker.com/reference/api/docker_remote_api/
|
||||
|
||||
## 实践参考
|
||||
* Dockerfile 参考:https://docs.docker.com/reference/builder/
|
||||
* Dockerfile 最佳实践:https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
|
||||
|
||||
## 技术交流
|
||||
* Docker 邮件列表: https://groups.google.com/forum/#!forum/docker-user
|
||||
* Docker 的 IRC 频道: https://chat.freenode.net#docker
|
||||
* Docker 的 Twitter 主页: https://twitter.com/docker
|
||||
|
||||
## 其它
|
||||
* Docker 的 StackOverflow 问答主页: https://stackoverflow.com/search?q=docker
|
@ -1,2 +0,0 @@
|
||||
# 常见仓库介绍
|
||||
本章将介绍常见的一些仓库和镜像的功能,使用方法和生成它们的 Dockerfile 等。包括 Ubuntu、CentOS、MySQL、MongoDB、Redis、Nginx、Wordpress、Node.js 等。
|
@ -1,17 +0,0 @@
|
||||
## [CentOS](https://registry.hub.docker.com/_/centos/)
|
||||
|
||||
### 基本信息
|
||||
[CentOS](https://en.wikipedia.org/wiki/CentOS) 是流行的 Linux 发行版,其软件包大多跟 RedHat 系列保持一致。
|
||||
该仓库提供了 CentOS 从 5 ~ 7 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
默认会启动一个最小化的 CentOS 环境。
|
||||
```
|
||||
$ sudo docker run --name some-centos -i -t centos bash
|
||||
bash-4.2#
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
* [CentOS 5 版本](https://github.com/CentOS/sig-cloud-instance-images/blob/2e5a9c4e8b7191b393822e4b9e98820db5638a77/docker/Dockerfile)
|
||||
* [CentOS 6 版本](https://github.com/CentOS/sig-cloud-instance-images/blob/8717e33ea5432ecb33d7ecefe8452a973715d037/docker/Dockerfile)
|
||||
* [CentOS 7 版本](https://github.com/CentOS/sig-cloud-instance-images/blob/af7a1b9f8f30744360a10fe44c53a1591bef26f9/docker/Dockerfile)
|
@ -1,26 +0,0 @@
|
||||
## [MongoDB](https://registry.hub.docker.com/_/mongo/)
|
||||
|
||||
### 基本信息
|
||||
[MongoDB](https://en.wikipedia.org/wiki/MongoDB) 是开源的 NoSQL 数据库实现。
|
||||
该仓库提供了 MongoDB 2.2 ~ 2.7 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
默认会在 `27017` 端口启动数据库。
|
||||
```
|
||||
$ sudo docker run --name some-mongo -d mongo
|
||||
```
|
||||
|
||||
使用其他应用连接到容器,可以用
|
||||
```
|
||||
$ sudo docker run --name some-app --link some-mongo:mongo -d application-that-uses-mongo
|
||||
```
|
||||
或者通过 `mongo`
|
||||
```
|
||||
$ sudo docker run -it --link some-mongo:mongo --rm mongo sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
* [2.2 版本](https://github.com/docker-library/mongo/blob/77c841472ccb6cc87fea1218269d097405edc6cb/2.2/Dockerfile)
|
||||
* [2.4 版本](https://github.com/docker-library/mongo/blob/807078cb7b5f0289f6dabf9f6875d5318122bc30/2.4/Dockerfile)
|
||||
* [2.6 版本](https://github.com/docker-library/mongo/blob/77c841472ccb6cc87fea1218269d097405edc6cb/2.6/Dockerfile)
|
||||
* [2.7 版本](https://github.com/docker-library/mongo/blob/807078cb7b5f0289f6dabf9f6875d5318122bc30/2.7/Dockerfile)
|
@ -1,23 +0,0 @@
|
||||
## [MySQL](https://registry.hub.docker.com/_/mysql/)
|
||||
|
||||
### 基本信息
|
||||
[MySQL](https://en.wikipedia.org/wiki/MySQL) 是开源的关系数据库实现。
|
||||
该仓库提供了 MySQL 各个版本的镜像,包括 5.6 系列、5.7 系列等。
|
||||
|
||||
### 使用方法
|
||||
默认会在 `3306` 端口启动数据库。
|
||||
```
|
||||
$ sudo docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
|
||||
```
|
||||
之后就可以使用其它应用来连接到该容器。
|
||||
```
|
||||
$ sudo docker run --name some-app --link some-mysql:mysql -d application-that-uses-mysql
|
||||
```
|
||||
或者通过 `mysql`。
|
||||
```
|
||||
$ sudo docker run -it --link some-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
* [5.6 版本](https://github.com/docker-library/mysql/blob/7461a52b43f06839a4d8723ae8841f4cb616b3d0/5.6/Dockerfile)
|
||||
* [5.7 版本](https://github.com/docker-library/mysql/blob/7461a52b43f06839a4d8723ae8841f4cb616b3d0/5.7/Dockerfile)
|
@ -1,34 +0,0 @@
|
||||
## [Nginx](https://registry.hub.docker.com/_/nginx/)
|
||||
|
||||
### 基本信息
|
||||
[Nginx](https://en.wikipedia.org/wiki/Nginx) 是开源的高效的 Web 服务器实现,支持 HTTP、HTTPS、SMTP、POP3、IMAP 等协议。
|
||||
该仓库提供了 Nginx 1.0 ~ 1.7 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
下面的命令将作为一个静态页面服务器启动。
|
||||
```
|
||||
$ sudo docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx
|
||||
```
|
||||
用户也可以不使用这种映射方式,通过利用 Dockerfile 来直接将静态页面内容放到镜像中,内容为
|
||||
```
|
||||
FROM nginx
|
||||
COPY static-html-directory /usr/share/nginx/html
|
||||
```
|
||||
之后生成新的镜像,并启动一个容器。
|
||||
```
|
||||
$ sudo docker build -t some-content-nginx .
|
||||
$ sudo docker run --name some-nginx -d some-content-nginx
|
||||
```
|
||||
开放端口,并映射到本地的 `8080` 端口。
|
||||
```
|
||||
sudo docker run --name some-nginx -d -p 8080:80 some-content-nginx
|
||||
```
|
||||
|
||||
Nginx的默认配置文件路径为 `/etc/nginx/nginx.conf`,可以通过映射它来使用本地的配置文件,例如
|
||||
```
|
||||
docker run --name some-nginx -v /some/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
|
||||
```
|
||||
使用配置文件时,为了在容器中正常运行,需要保持 `daemon off;`。
|
||||
|
||||
### Dockerfile
|
||||
* [1 ~ 1.7 版本](https://github.com/nginxinc/docker-nginx/blob/3713a0157083eb4776e71f5a5aef4b2a5bc03ab1/Dockerfile)
|
@ -1,28 +0,0 @@
|
||||
## [Node.js](https://registry.hub.docker.com/_/node/)
|
||||
|
||||
### 基本信息
|
||||
[Node.js](https://en.wikipedia.org/wiki/Node.js)是基于 JavaScript 的可扩展服务端和网络软件开发平台。
|
||||
该仓库提供了 Node.js 0.8 ~ 0.11 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
在项目中创建一个 Dockerfile。
|
||||
```
|
||||
FROM node:0.10-onbuild
|
||||
# replace this with your application's default port
|
||||
EXPOSE 8888
|
||||
```
|
||||
然后创建镜像,并启动容器
|
||||
```
|
||||
$ sudo docker build -t my-nodejs-app
|
||||
$ sudo docker run -it --rm --name my-running-app my-nodejs-app
|
||||
```
|
||||
|
||||
也可以直接运行一个简单容器。
|
||||
```
|
||||
$ sudo docker run -it --rm --name my-running-script -v "$(pwd)":/usr/src/myapp -w /usr/src/myapp node:0.10 node your-daemon-or-script.js
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
* [0.8 版本](https://github.com/docker-library/node/blob/d017d679e92e84a810c580cdb29fcdbba23c2bb9/0.8/Dockerfile)
|
||||
* [0.10 版本](https://github.com/docker-library/node/blob/913a225f2fda34d6a811fac1466e4f09f075fcf6/0.10/Dockerfile)
|
||||
* [0.11 版本](https://github.com/docker-library/node/blob/d017d679e92e84a810c580cdb29fcdbba23c2bb9/0.11/Dockerfile)
|
@ -1,29 +0,0 @@
|
||||
## [Redis](https://registry.hub.docker.com/_/redis/)
|
||||
|
||||
### 基本信息
|
||||
[Redis](https://en.wikipedia.org/wiki/Redis) 是开源的内存 Key-Value 数据库实现。
|
||||
该仓库提供了 Redis 2.6 ~ 2.8.9 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
默认会在 `6379` 端口启动数据库。
|
||||
```
|
||||
$ sudo docker run --name some-redis -d redis
|
||||
```
|
||||
另外还可以启用 [持久存储](http://redis.io/topics/persistence)。
|
||||
```
|
||||
$ sudo docker run --name some-redis -d redis redis-server --appendonly yes
|
||||
```
|
||||
默认数据存储位置在 `VOLUME/data`。可以使用 `--volumes-from some-volume-container` 或 `-v /docker/host/dir:/data` 将数据存放到本地。
|
||||
|
||||
使用其他应用连接到容器,可以用
|
||||
```
|
||||
$ sudo docker run --name some-app --link some-redis:redis -d application-that-uses-redis
|
||||
```
|
||||
或者通过 `redis-cli`
|
||||
```
|
||||
$ sudo docker run -it --link some-redis:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
* [2.6 版本](https://github.com/docker-library/redis/blob/02d9cd887a4e0d50db4bb085eab7235115a6fe4a/2.6.17/Dockerfile)
|
||||
* [最新 2.8 版本](https://github.com/docker-library/redis/blob/d0665bb1bbddd4cc035dbc1fc774695fa534d648/2.8.13/Dockerfile)
|
@ -1,17 +0,0 @@
|
||||
## [Ubuntu](https://registry.hub.docker.com/_/ubuntu/)
|
||||
|
||||
### 基本信息
|
||||
[Ubuntu](https://en.wikipedia.org/wiki/Ubuntu) 是流行的 Linux 发行版,其自带软件版本往往较新一些。
|
||||
该仓库提供了 Ubuntu从12.04 ~ 14.10 各个版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
默认会启动一个最小化的 Ubuntu 环境。
|
||||
```
|
||||
$ sudo docker run --name some-ubuntu -i -t ubuntu
|
||||
root@523c70904d54:/#
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
* [12.04 版本](https://github.com/tianon/docker-brew-ubuntu-core/blob/2b105575647a7e2030ff344d427c3920b89e17a9/precise/Dockerfile)
|
||||
* [14.04 版本](https://github.com/tianon/docker-brew-ubuntu-core/blob/2b105575647a7e2030ff344d427c3920b89e17a9/trusty/Dockerfile)
|
||||
* [14.10 版本](https://github.com/tianon/docker-brew-ubuntu-core/blob/2b105575647a7e2030ff344d427c3920b89e17a9/utopic/Dockerfile)
|
@ -1,19 +0,0 @@
|
||||
## [WordPress](https://registry.hub.docker.com/_/wordpress/)
|
||||
|
||||
### 基本信息
|
||||
[WordPress](https://en.wikipedia.org/wiki/WordPress) 是开源的 Blog 和内容管理系统框架,它基于 PhP 和 MySQL。
|
||||
该仓库提供了 WordPress 4.0 版本的镜像。
|
||||
|
||||
### 使用方法
|
||||
启动容器需要 MySQL 的支持,默认端口为 `80`。
|
||||
```
|
||||
$ sudo docker run --name some-wordpress --link some-mysql:mysql -d wordpress
|
||||
```
|
||||
启动 WordPress 容器时可以指定的一些环境参数包括
|
||||
* `-e WORDPRESS_DB_USER=...` 缺省为 “root”
|
||||
* `-e WORDPRESS_DB_PASSWORD=...` 缺省为连接 mysql 容器的环境变量 `MYSQL_ROOT_PASSWORD` 的值
|
||||
* `-e WORDPRESS_DB_NAME=...` 缺省为 “wordpress”
|
||||
* `-e WORDPRESS_AUTH_KEY=...`, `-e WORDPRESS_SECURE_AUTH_KEY=...`, `-e WORDPRESS_LOGGED_IN_KEY=...`, `-e WORDPRESS_NONCE_KEY=...`, `-e WORDPRESS_AUTH_SALT=...`, `-e WORDPRESS_SECURE_AUTH_SALT=...`, `-e WORDPRESS_LOGGED_IN_SALT=...`, `-e WORDPRESS_NONCE_SALT=...` 缺省为随机 sha1 串
|
||||
|
||||
### Dockerfile
|
||||
* [4.0 版本](https://github.com/docker-library/wordpress/blob/aee00669e7c43f435f021cb02871bffd63d5677a/Dockerfile)
|
@ -1,7 +0,0 @@
|
||||
# 资源链接
|
||||
* Docker 主站点: https://www.docker.io
|
||||
* Docker 注册中心API: http://docs.docker.com/reference/api/registry_api/
|
||||
* Docker Hub API: http://docs.docker.com/reference/api/docker-io_api/
|
||||
* Docker 远端应用API: http://docs.docker.com/reference/api/docker_remote_api/
|
||||
* Dockerfile 参考:https://docs.docker.com/reference/builder/
|
||||
* Dockerfile 最佳实践:https://docs.docker.com/articles/dockerfile_best-practices/
|
Loading…
Reference in New Issue
Block a user