diff --git a/CHANGELOG.md b/CHANGELOG.md index cbc2e53..5c33154 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ * 增加 Docker 中文资源链接 * 增加介绍基于 Docker 的 CI/CD 工具 `Drone` * 增加 `docker secret` 相关内容 + * 增加 `docker config` 相关内容 + * 增加 `LinuxKit` 相关内容 * 更新 `CoreOS` 章节 * 更新 `etcd` 章节,基于 3.x 版本 @@ -19,6 +21,9 @@ * 替换 `docker ps` 命令为 `docker container ls` * 替换 `docker images` 命令为 `docker image ls` + * 修改 `安装 Docker` 一节中部分文字表述 + + * 移除历史遗留文件和错误的文件 * 优化文字排版 * 调整目录结构 * 修复内容逻辑错误 diff --git a/SUMMARY.md b/SUMMARY.md index fb4d7c7..da8be8a 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -86,6 +86,7 @@ * [部署服务](swarm_mode/deploy.md) * [使用 compose 文件](swarm_mode/stack.md) * [管理敏感数据](swarm_mode/secret.md) + * [管理配置信息](swarm_mode/config.md) * [安全](security/README.md) * [内核命名空间](security/kernel_ns.md) * [控制组](security/control_group.md) @@ -137,6 +138,8 @@ * [本章小结](cases/os/summary.md) * [实战案例-CI/CD](cases/ci/README.md) * [Drone](cases/ci/drone.md) +* [Docker 开源项目](opensource/README.md) + * [LinuxKit](opensource/linuxkit.md) * [附录](appendix/README.md) * [附录一:常见问题总结](appendix/faq/README.md) * [附录二:热门镜像介绍](appendix/repo/README.md) @@ -149,6 +152,6 @@ * [WordPress](appendix/repo/wordpress.md) * [Node.js](appendix/repo/nodejs.md) * [附录三:Docker 命令查询](appendix/command/README.md) - * [附录四:Dockerfile 最佳实践](appendix/best_practices.md)) + * [附录四:Dockerfile 最佳实践](appendix/best_practices.md) * [附录五:资源链接](appendix/resources/README.md) * [附录六:Docker 中文资源](appendix/resources/cn.md) diff --git a/_local/.bashrc_docker b/_local/.bashrc_docker deleted file mode 100644 index ed0df3c..0000000 --- a/_local/.bashrc_docker +++ /dev/null @@ -1,49 +0,0 @@ -# Some useful commands to use docker. -# Author: yeasy@github -# Created:2014-09-25 - -alias docker-pid="sudo docker inspect --format '{{.State.Pid}}'" -alias docker-ip="sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}'" - -#the implementation refs from https://github.com/jpetazzo/nsenter/blob/master/docker-enter -function docker-enter() { - #if [ -e $(dirname "$0")/nsenter ]; then - #Change for centos bash running - if [ -e $(dirname '$0')/nsenter ]; then - # with boot2docker, nsenter is not in the PATH but it is in the same folder - NSENTER=$(dirname "$0")/nsenter - else - # if nsenter has already been installed with path notified, here will be clarified - NSENTER=$(which nsenter) - #NSENTER=nsenter - fi - [ -z "$NSENTER" ] && echo "WARN Cannot find nsenter" && return - - if [ -z "$1" ]; then - echo "Usage: `basename "$0"` CONTAINER [COMMAND [ARG]...]" - echo "" - echo "Enters the Docker CONTAINER and executes the specified COMMAND." - echo "If COMMAND is not specified, runs an interactive shell in CONTAINER." - else - PID=$(sudo docker inspect --format "{{.State.Pid}}" "$1") - if [ -z "$PID" ]; then - echo "WARN Cannot find the given container" - return - fi - shift - - OPTS="--target $PID --mount --uts --ipc --net --pid" - - if [ -z "$1" ]; then - # No command given. - # Use su to clear all host environment variables except for TERM, - # initialize the environment variables HOME, SHELL, USER, LOGNAME, PATH, - # and start a login shell. - #sudo $NSENTER "$OPTS" su - root - sudo $NSENTER --target $PID --mount --uts --ipc --net --pid su - root - else - # Use env to clear all host environment variables. - sudo $NSENTER --target $PID --mount --uts --ipc --net --pid env -i $@ - fi - fi -} diff --git a/_local/docker_manual_waitfish.pdf b/_local/docker_manual_waitfish.pdf deleted file mode 100644 index add8577..0000000 Binary files a/_local/docker_manual_waitfish.pdf and /dev/null differ diff --git a/_local/pull_all.sh b/_local/pull_all.sh deleted file mode 100644 index 8240c08..0000000 --- a/_local/pull_all.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# This script will update all local images -# See: https://github.com/yeasy/docker_practice/blob/master/_local/pull_all.sh -# Usage: pull_all -# Author: yeasy@github -# Create: 2014-09-23 - -for image in `sudo docker images|grep -v "REPOSITORY"|grep -v ""|awk '{print $1":"$2}'` -do - sudo docker pull $image -done - diff --git a/_local/push_all.sh b/_local/push_all.sh deleted file mode 100644 index 2ec1aee..0000000 --- a/_local/push_all.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -# This script will upload all local images to a registry server ($registry is the default value). -# This script requires the push_images, which can be found at https://github.com/yeasy/docker_practice/blob/master/_local/push_images.sh -# Usage: push_all -# Author: yeasy@github -# Create: 2014-09-23 - -for image in `sudo docker images|grep -v "REPOSITORY"|grep -v ""|awk '{print $1":"$2}'` -do - push_images $image -done - diff --git a/_local/push_images.sh b/_local/push_images.sh deleted file mode 100644 index 5e7516f..0000000 --- a/_local/push_images.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh - -# This script will upload the given local images to a registry server ($registry is the default value). -# See: https://github.com/yeasy/docker_practice/blob/master/_local/push_images.sh -# Usage: push_images image1 [image2...] -# Author: yeasy@github -# Create: 2014-09-23 - -#The registry server address where you want push the images into -registry=127.0.0.1:5000 - -### DO NOT MODIFY THE FOLLOWING PART, UNLESS YOU KNOW WHAT IT MEANS ### -echo_r () { - [ $# -ne 1 ] && return 0 - echo -e "\033[31m$1\033[0m" -} -echo_g () { - [ $# -ne 1 ] && return 0 - echo -e "\033[32m$1\033[0m" -} -echo_y () { - [ $# -ne 1 ] && return 0 - echo -e "\033[33m$1\033[0m" -} -echo_b () { - [ $# -ne 1 ] && return 0 - echo -e "\033[34m$1\033[0m" -} - -usage() { - sudo docker images - echo "Usage: $0 registry1:tag1 [registry2:tag2...]" -} - -[ $# -lt 1 ] && usage && exit - -echo_b "The registry server is $registry" - - -for image in "$@" -do - echo_b "Uploading $image..." - sudo docker tag $image $registry/$image - sudo docker push $registry/$image - sudo docker rmi $registry/$image - echo_g "Done" -done diff --git a/appendix_command/README.md b/appendix_command/README.md deleted file mode 100644 index 2e69ca1..0000000 --- a/appendix_command/README.md +++ /dev/null @@ -1,126 +0,0 @@ -# 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=://:指定 `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` 来查看这些命令的具体用法。 - -* 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 的命令 -![命令周期](../_images/cmd_logic.png) diff --git a/install/centos.md b/install/centos.md index 70b916e..fb0907d 100644 --- a/install/centos.md +++ b/install/centos.md @@ -27,9 +27,7 @@ $ sudo yum install -y yum-utils \ lvm2 ``` -鉴于国内网络问题,强烈建议使用国内源,下面先介绍国内源的使用。 - -#### 国内源 +鉴于国内网络问题,强烈建议使用国内源,官方源请在注释中查看。 执行下面的命令添加 `yum` 软件源: @@ -37,16 +35,12 @@ $ sudo yum install -y yum-utils \ $ sudo yum-config-manager \ --add-repo \ https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo -``` ->以上命令会添加稳定版本的 Docker CE yum 源。从 Docker 17.06 开始,edge test 版本的 yum 源也会包含稳定版本的 Docker CE。 -#### 官方源 - -```bash -$ sudo yum-config-manager \ - --add-repo \ - https://download.docker.com/linux/centos/docker-ce.repo +# 官方源 +# $ sudo yum-config-manager \ +# --add-repo \ +# https://download.docker.com/linux/centos/docker-ce.repo ``` 如果需要最新版本的 Docker CE 请使用以下命令: @@ -55,6 +49,8 @@ $ sudo yum-config-manager \ $ sudo yum-config-manager --enable docker-ce-edge ``` +如果需要测试版本的 Docker CE 请使用以下命令: + ```bash $ sudo yum-config-manager --enable docker-ce-test ``` diff --git a/install/debian.md b/install/debian.md index 151d359..b6a9ce5 100644 --- a/install/debian.md +++ b/install/debian.md @@ -56,14 +56,16 @@ $ sudo apt-get install \ ``` -鉴于国内网络问题,强烈建议使用国内源,下面先介绍国内源的使用。 - -#### 国内源 +鉴于国内网络问题,强烈建议使用国内源,官方源请在注释中查看。 为了确认所下载软件包的合法性,需要添加软件源的 GPG 密钥。 ```bash $ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add - + + +# 官方源 +# $ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - ``` 然后,我们需要向 `source.list` 中添加 Docker CE 软件源: @@ -73,20 +75,16 @@ $ sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/$(. /etc/os-release; echo "$ID") \ $(lsb_release -cs) \ stable" + + +# 官方源 +# $ sudo add-apt-repository \ +# "deb [arch=amd64] https://download.docker.com/linux/debian \ +# $(lsb_release -cs) \ +# stable" ``` ->以上命令会添加稳定版本的 Docker CE APT 镜像源,如果需要最新版本的 Docker CE 请将 stable 改为 edge 或者 test。从 Docker 17.06 开始,edge test 版本的 APT 镜像源也会包含稳定版本的 Docker CE。 - -#### 官方源 - -```bash -$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - - -$ sudo add-apt-repository \ - "deb [arch=amd64] https://download.docker.com/linux/debian \ - $(lsb_release -cs) \ - stable" -``` +>以上命令会添加稳定版本的 Docker CE APT 镜像源,如果需要最新或者测试版本的 Docker CE 请将 stable 改为 edge 或者 test。从 Docker 17.06 开始,edge test 版本的 APT 镜像源也会包含稳定版本的 Docker CE。 Debian 7 需要进行额外的操作: diff --git a/install/raspberry-pi.md b/install/raspberry-pi.md index a85b83e..bd2d388 100644 --- a/install/raspberry-pi.md +++ b/install/raspberry-pi.md @@ -28,14 +28,16 @@ $ sudo apt-get install \ software-properties-common ``` -鉴于国内网络问题,强烈建议使用国内源,下面先介绍国内源的使用。 - -#### 国内源 +鉴于国内网络问题,强烈建议使用国内源,官方源请在注释中查看。 为了确认所下载软件包的合法性,需要添加软件源的 GPG 密钥。 ```bash $ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/raspbian/gpg | sudo apt-key add - + + +# 官方源 +# $ curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add - ``` 然后,我们需要向 `source.list` 中添加 Docker CE 软件源: @@ -45,21 +47,17 @@ $ sudo add-apt-repository \ "deb [arch=armhf] https://mirrors.ustc.edu.cn/docker-ce/linux/raspbian \ $(lsb_release -cs) \ stable" + + +# 官方源 +# $ sudo add-apt-repository \ +# "deb [arch=armhf] https://download.docker.com/linux/raspbian \ +# $(lsb_release -cs) \ +# stable" ``` >以上命令会添加稳定版本的 Docker CE APT 镜像源,如果需要最新版本的 Docker CE 请将 stable 改为 edge 或者 test。从 Docker 17.06 开始,edge test 版本的 APT 镜像源也会包含稳定版本的 Docker CE。 -#### 官方源 - -```bash -$ curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add - - -$ sudo add-apt-repository \ - "deb [arch=armhf] https://download.docker.com/linux/raspbian \ - $(lsb_release -cs) \ - stable" -``` - #### 安装 Docker CE 更新 apt 软件包缓存,并安装 `docker-ce`。 diff --git a/install/ubuntu.md b/install/ubuntu.md index df7a916..cb60aae 100644 --- a/install/ubuntu.md +++ b/install/ubuntu.md @@ -52,14 +52,16 @@ $ sudo apt-get install \ software-properties-common ``` -鉴于国内网络问题,强烈建议使用国内源,下面先介绍国内源的使用。 - -#### 国内源 +鉴于国内网络问题,强烈建议使用国内源,官方源请在注释中查看。 为了确认所下载软件包的合法性,需要添加软件源的 GPG 密钥。 ```bash $ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - + + +# 官方源 +# $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - ``` 然后,我们需要向 `source.list` 中添加 Docker 软件源 @@ -69,20 +71,16 @@ $ sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \ $(lsb_release -cs) \ stable" + + +# 官方源 +# $ sudo add-apt-repository \ +# "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ +# $(lsb_release -cs) \ +# stable" ``` ->以上命令会添加稳定版本的 Docker CE APT 镜像源,如果需要最新版本的 Docker CE 请将 stable 改为 edge 或者 test。从 Docker 17.06 开始,edge test 版本的 APT 镜像源也会包含稳定版本的 Docker。 - -#### 官方源 - -```bash -$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - -$ sudo add-apt-repository \ - "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ - $(lsb_release -cs) \ - stable" -``` +>以上命令会添加稳定版本的 Docker CE APT 镜像源,如果需要最新或者测试版本的 Docker CE 请将 stable 改为 edge 或者 test。从 Docker 17.06 开始,edge test 版本的 APT 镜像源也会包含稳定版本的 Docker。 #### 安装 Docker CE diff --git a/opensource/README.md b/opensource/README.md new file mode 100644 index 0000000..d9f5450 --- /dev/null +++ b/opensource/README.md @@ -0,0 +1,3 @@ +# Docker 开源项目 + +本章介绍 Docker 开源的项目。随着 Docker 功能的越来越多,Docker 也加快了开源的步伐,Docker 未来会将引擎拆分为更多开放组件,对用于组装 Docker 产品的各种新型工具与组件进行开源并供技术社区使用。 diff --git a/opensource/linuxkit.md b/opensource/linuxkit.md new file mode 100644 index 0000000..a4513c0 --- /dev/null +++ b/opensource/linuxkit.md @@ -0,0 +1,51 @@ +## LinuxKit + +`LinuxKit` 这个工具可以将多个 Docker 镜像组成一个最小化、可自由定制的 Linux 系统,最后的生成的系统只有几十 M 大小,可以很方便的在云端进行部署。 + +下面我们在 macOS 上通过实例,来编译并运行一个全部由 Docker 镜像组成的包含 nginx 服务的 Linux 系统。 + +### 安装 Linuxkit + +```bash +$ brew tap linuxkit/linuxkit + +$ brew install --HEAD linuxkit +``` + +### 克隆源代码 + +```bash +$ git clone -b master --depth=1 https://github.com/linuxkit/linuxkit.git + +$ cd linuxkit +``` + +### 编译 Linux 系统 + +LinuxKit 通过 `yaml` 文件配置。 + +我们来查看 `linuxkit.yml` 文件,了解各个字段的作用。 + +`kernel` 字段定义了内核版本。 + +`init` 字段中配置系统启动时的初始化顺序。 + +`onboot` 字段配置系统级的服务。 + +`services` 字段配置镜像启动后运行的服务。 + +`files` 字段配置制作镜像时打包入镜像中的文件。 + +```bash +$ linuxkit build linuxkit.yml +``` + +### 启动 Linux 系统 + +编译成功后,接下来启动这个 Linux 系统。 + +```bash +$ linuxkit run -publish 8080:80/tcp linuxkit +``` + +接下来在浏览器中打开 `127.0.0.1:8080` 即可看到 nginx 默认页面。 diff --git a/swarm_mode/config.md b/swarm_mode/config.md new file mode 100644 index 0000000..f34343c --- /dev/null +++ b/swarm_mode/config.md @@ -0,0 +1,52 @@ +## 在 Swarm 集群中管理配置数据 + +在动态的、大规模的分布式集群上,管理和分发配置文件也是很重要的工作。传统的配置文件分发方式(如配置文件放入镜像中,设置环境变量,volume 动态挂载等)都降低了镜像的通用性。 + +在 Docker 17.06 以上版本中,Docker 新增了 `docker config` 子命令来管理集群中的配置信息,以后你无需将配置文件放入镜像或挂载到容器中就可实现对服务的配置。 + +>注意:`docker config` 仅能在 Swarm 集群中使用。 + +这里我们以在 Swarm 集群中部署 `redis` 服务为例。 + +### 创建 config + +新建 `redis.conf` 文件 + +```bash +port 6380 +``` + +此项配置 Redis 监听 `6380` 端口 + +我们使用 `docker config create` 命令创建 `config` + +```bash +$ docker config create redis.conf redis.conf +``` + +### 查看 config + +使用 `docker config ls` 命令来查看 `secret` + +```bash +ID NAME CREATED UPDATED +yod8fx8iiqtoo84jgwadp86yk redis.conf 4 seconds ago 4 seconds ago +``` + +### 创建 redis 服务 + +```bash +$ docker service create \ + --name redis \ + # --config source=redis.conf,target=/etc/redis.conf \ + --config redis.conf \ + -p 6379:6380 \ + redis:latest \ + redis-server /redis.conf +``` + +如果你没有在 `target` 中显式的指定路径时,默认的 `redis.conf` 以 `tmpfs` 文件系统挂载到容器的 `/config.conf`。 + +经过测试,redis 可以正常使用。 + +以前我们通过监听主机目录来配置 Redis,就需要在集群的每个节点放置该文件,如果采用 `docker config` 来管理服务的配置信息,我们只需在集群中的管理节点创建 `config`,当部署服务时,集群会自动的将配置文件分发到运行服务的各个节点中,大大降低了配置信息的管理和分发难度。