Merge pull request #273 from khs1994/master

pull/277/head
Baohua Yang 2017-12-02 08:12:05 +08:00 committed by GitHub
commit 28cf0432f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 63 additions and 62 deletions

View File

@ -23,7 +23,10 @@ $ docker run --name some-app --link some-mongo:mongo -d application-that-uses-mo
或者通过 `mongo`
```bash
$ docker run -it --link some-mongo:mongo --rm mongo sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'
$ docker run -it --rm \
--link some-mongo:mongo \
mongo \
sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'
```
### Dockerfile

View File

@ -23,7 +23,10 @@ $ docker run --name some-app --link some-mysql:mysql -d application-that-uses-my
或者通过 `mysql`
```bash
$ 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"'
$ docker run -it --rm \
--link some-mysql:mysql \
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

View File

@ -31,17 +31,18 @@ $ docker run --name some-nginx -d some-content-nginx
开放端口,并映射到本地的 `8080` 端口。
```bash
docker run --name some-nginx -d -p 8080:80 some-content-nginx
$ docker run --name some-nginx -d -p 8080:80 some-content-nginx
```
Nginx的默认配置文件路径为 `/etc/nginx/nginx.conf`,可以通过映射它来使用本地的配置文件,例如
```bash
docker run --name some-nginx -v /some/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
$ docker run -d \
--name some-nginx \
-v /some/nginx.conf:/etc/nginx/nginx.conf:ro \
nginx
```
使用配置文件时,为了在容器中正常运行,需要保持 `daemon off;`
### Dockerfile
请到 https://github.com/docker-library/docs/tree/master/nginx 查看。

View File

@ -26,7 +26,13 @@ $ docker run -it --rm --name my-running-app my-nodejs-app
也可以直接运行一个简单容器。
```bash
$ 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
$ docker run -it --rm \
--name my-running-script \
# -v "$(pwd)":/usr/src/myapp \
--mount type=bind,src=`$(pwd)`,target=/usr/src/myapp \
-w /usr/src/myapp \
node:9-alpine \
node your-daemon-or-script.js
```
### Dockerfile

View File

@ -31,7 +31,10 @@ $ docker run --name some-app --link some-redis:redis -d application-that-uses-re
或者通过 `redis-cli`
```bash
$ 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"'
$ docker run -it --rm \
--link some-redis:redis \
redis \
sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
```
### Dockerfile

View File

@ -14,7 +14,7 @@
下表是官方镜像的大小比较:
```sh
```bash
REPOSITORY TAG IMAGE ID VIRTUAL SIZE
alpine latest 4e38e38c8ce0 4.799 MB
debian latest 4d6ce913b130 84.98 MB
@ -26,21 +26,11 @@ centos latest 8efe422e6104 210 MB
由于镜像很小,下载时间往往很短,读者可以直接使用 `docker run` 指令直接运行一个 `Alpine` 容器,并指定运行的 Linux 指令,例如:
```sh
```bash
$ docker run alpine echo '123'
123
```
笔者使用 time 工具来测试下在本地没有提前 pull 镜像情况下,执行 echo 命令的时间,仅需要 3 秒左右。
```sh
$ time docker run alpine echo '123'Unable to find image 'alpine:latest' locallylatest: Pulling from library/alpine
e110a4a17941: Pull completeDigest: sha256:3dcdb92d7432d56604d4545cbd324b14e647b313626d99b889d0626de158f73aStatus: Downloaded newer image for alpine:latest123
real 0m3.367s user 0m0.040s sys 0m0.007s
```
### 迁移至 `Alpine` 基础镜像
目前,大部分 Docker 官方镜像都已经支持 Alpine 作为基础镜像,可以很容易进行迁移。
@ -53,21 +43,20 @@ real 0m3.367s user 0m0.040s sys 0m0.007s
另外,如果使用 `Alpine` 镜像替换 `Ubuntu` 基础镜像,安装软件包时需要用 apk 包管理器替换 apt 工具,如
```sh
```bash
$ apk add --no-cache <package>
```
`Alpine` 中软件安装包的名字可能会与其他发行版有所不同,可以在 `https://pkgs.alpinelinux.org/packages` 网站搜索并确定安装包名称。如果需要的安装包不在主索引内,但是在测试或社区索引中。那么可以按照以下方法使用这些安装包。
```sh
```bash
$ echo "http://dl-4.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
$ apk --update add --no-cache <package>
```
### 相关资源
* `Apline` 官网:`http://alpinelinux.org/`
* `Apline` 官方仓库:`https://github.com/alpinelinux`
* `Apline` 官方镜像:`https://hub.docker.com/_/alpine/`
* `Apline` 官方镜像仓库:`https://github.com/gliderlabs/docker-alpine`
* `Alpine` 官网http://alpinelinux.org/
* `Alpine` 官方仓库https://github.com/alpinelinux
* `Alpine` 官方镜像https://hub.docker.com/_/alpine/
* `Alpine` 官方镜像仓库https://github.com/gliderlabs/docker-alpine

View File

@ -12,7 +12,7 @@ BusyBox 可运行于多款 POSIX 环境的操作系统中,如 Linux包括 A
在 Docker Hub 中搜索 busybox 相关的镜像。
```sh
```bash
$ docker search busybox
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
busybox Busybox base image. 755 [OK]
@ -26,7 +26,7 @@ azukiapp/busybox This image is meant to be used as the base...
读者可以看到最受欢迎的镜像同时带有 OFFICIAL 标记,说明它是官方镜像。用户使用 docker pull 指令下载镜像 `busybox:latest`
```sh
```bash
$ docker pull busybox:latest
busybox:latest: The image you are pulling has been verified
e433a6c5b276: Pull complete
@ -38,7 +38,7 @@ Status: Downloaded newer image for busybox:latest
下载后,可以看到 busybox 镜像只有2.433 MB
```sh
```bash
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
busybox latest e72ac664f4f0 6 weeks ago 2.433 MB
@ -48,7 +48,7 @@ busybox latest e72ac664f4f0 6 weeks ago
启动一个 busybox 容器,并在容器中执行 grep 命令。
```sh
```bash
$ docker run -it busybox
/ # grep
BusyBox v1.22.1 (2014-05-22 23:22:11 UTC) multi-call binary.
@ -83,7 +83,7 @@ Search for PATTERN in FILEs (or stdin)
查看容器内的挂载信息。
```sh
```bash
/ # mount
rootfs on / type rootfs (rw)
none on / type aufs (rw,relatime,si=b455817946f8505c)
@ -107,8 +107,7 @@ busybox 镜像虽然小巧,但包括了大量常见的 Linux 命令,读者
### 相关资源
* `Busybox` 官网:`https://busybox.net/`
* `Busybox` 官方仓库:`https://git.busybox.net/busybox/`
* `Busybox` 官方镜像:`https://hub.docker.com/_/busybox/`
* `Busybox` 官方仓库:`https://github.com/docker-library/busybox`
* `Busybox` 官网https://busybox.net/
* `Busybox` 官方仓库https://git.busybox.net/busybox/
* `Busybox` 官方镜像https://hub.docker.com/_/busybox/
* `Busybox` 官方仓库https://github.com/docker-library/busybox

View File

@ -66,11 +66,11 @@ Fedora release 24 (Twenty Four)
### 相关资源
* `Fedora` 官网:`https://getfedora.org/`
* `Fedora` 官方仓库:`https://github.com/fedora-infra`
* `Fedora` 官方镜像:`https://hub.docker.com/_/fedora/`
* `Fedora` 官方镜像仓库:`https://github.com/fedora-cloud/docker-brew-fedora`
* `CentOS` 官网:`https://getfedora.org/`
* `CentOS` 官方仓库:`https://github.com/CentOS`
* `CentOS` 官方镜像:`https://hub.docker.com/_/centos/`
* `CentOS` 官方镜像仓库:`https://github.com/CentOS/CentOS-Dockerfiles`
* `Fedora` 官网https://getfedora.org/
* `Fedora` 官方仓库https://github.com/fedora-infra
* `Fedora` 官方镜像https://hub.docker.com/_/fedora/
* `Fedora` 官方镜像仓库https://github.com/fedora-cloud/docker-brew-fedora
* `CentOS` 官网https://getfedora.org/
* `CentOS` 官方仓库https://github.com/CentOS
* `CentOS` 官方镜像https://hub.docker.com/_/centos/
* `CentOS` 官方镜像仓库https://github.com/CentOS/CentOS-Dockerfiles

View File

@ -159,12 +159,12 @@ root@7d93de07bf76:/# curl 127.0.0.1
### 相关资源
* `Debian` 官网:`https://www.debian.org/`
* `Neuro Debian` 官网:`http://neuro.debian.net/`
* `Debian` 官方仓库:`https://github.com/Debian`
* `Debian` 官方镜像:`https://hub.docker.com/_/debian/`
* `Debian` 官方镜像仓库:`https://github.com/tianon/docker-brew-debian/`
* `Ubuntu` 官网:`http://www.ubuntu.org.cn/global`
* `Ubuntu` 官方仓库:`https://github.com/ubuntu`
* `Ubuntu` 官方镜像:`https://hub.docker.com/_/ubuntu/`
* `Ubuntu` 官方镜像仓库:`https://github.com/tianon/docker-brew-ubuntu-core`
* `Debian` 官网https://www.debian.org/
* `Neuro Debian` 官网http://neuro.debian.net/
* `Debian` 官方仓库https://github.com/Debian
* `Debian` 官方镜像https://hub.docker.com/_/debian/
* `Debian` 官方镜像仓库https://github.com/tianon/docker-brew-debian/
* `Ubuntu` 官网http://www.ubuntu.org.cn/global
* `Ubuntu` 官方仓库https://github.com/ubuntu
* `Ubuntu` 官方镜像https://hub.docker.com/_/ubuntu/
* `Ubuntu` 官方镜像仓库https://github.com/tianon/docker-brew-ubuntu-core

View File

@ -1,3 +0,0 @@
docker_book
===========
Internal usage.

View File

@ -4,7 +4,7 @@
etcd 是 CoreOS 团队于 2013 年 6 月发起的开源项目它的目标是构建一个高可用的分布式键值key-value数据库基于 Go 语言实现。我们知道在分布式系统中各种服务的配置信息的管理分享服务的发现是一个很基本同时也是很重要的问题。CoreOS 项目就希望基于 etcd 来解决这一问题。
etcd 目前在 [github.com/coreos/etcd](https://github.com/coreos/etcd) 进行维护,即将发布 2.0.0 版本
etcd 目前在 [github.com/coreos/etcd](https://github.com/coreos/etcd) 进行维护。
受到 [Apache ZooKeeper](http://zookeeper.apache.org/) 项目和 [doozer](https://github.com/ha/doozerd) 项目的启发etcd 在设计的时候重点考虑了下面四个要素:
* 简单:支持 REST 风格的 HTTP+JSON API

View File

@ -14,7 +14,7 @@ ubuntu latest f753707788c5 4 weeks ago
ubuntu 14.04 1e0c3dd64ccd 4 weeks ago 188 MB
```
列表包含了仓库名、标签、镜像 ID、创建时间以及所占用的空间。
列表包含了 `仓库名``标签``镜像 ID``创建时间` 以及 `所占用的空间`
其中仓库名、标签在之前的基础概念章节已经介绍过了。**镜像 ID** 则是镜像的唯一标识,一个镜像可以对应多个**标签**。因此,在上面的例子中,我们可以看到 `ubuntu:16.04``ubuntu:latest` 拥有相同的 ID因为它们对应的是同一个镜像。

View File

@ -2,7 +2,7 @@
之前提到过,[Docker Hub](https://hub.docker.com/explore/) 上有大量的高质量的镜像可以用,这里我们就说一下怎么获取这些镜像并运行。
从 Docker Registry 获取镜像的命令是 `docker pull`。其命令格式为:
从 Docker 镜像仓库获取镜像的命令是 `docker pull`。其命令格式为:
```bash
docker pull [选项] [Docker Registry地址]<仓库名>:<标签>
@ -10,7 +10,7 @@ docker pull [选项] [Docker Registry地址]<仓库名>:<标签>
具体的选项可以通过 `docker pull --help` 命令看到,这里我们说一下镜像名称的格式。
* Docker Registry 地址:地址的格式一般是 `<域名/IP>[:端口号]`。默认地址是 Docker Hub。
* Docker 镜像仓库地址:地址的格式一般是 `<域名/IP>[:端口号]`。默认地址是 Docker Hub。
* 仓库名:如之前所说,这里的仓库名是两段式名称,即 `<用户名>/<软件名>`。对于 Docker Hub如果不给出用户名则默认为 `library`,也就是官方镜像。
比如:
@ -27,7 +27,7 @@ Digest: sha256:147913621d9cdea08853f6ba9116c2e27a3ceffecf3b492983ae97c3d643fbbe
Status: Downloaded newer image for ubuntu:14.04
```
上面的命令中没有给出 Docker Registry 地址,因此将会从 Docker Hub 获取镜像。而镜像名称是 `ubuntu:14.04`,因此将会获取官方镜像 `library/ubuntu` 仓库中标签为 `14.04` 的镜像。
上面的命令中没有给出 Docker 镜像仓库地址,因此将会从 Docker Hub 获取镜像。而镜像名称是 `ubuntu:14.04`,因此将会获取官方镜像 `library/ubuntu` 仓库中标签为 `14.04` 的镜像。
从下载过程中可以看到我们之前提及的分层存储的概念,镜像是由多层存储所构成。下载也是一层层的去下载,并非单一文件。下载过程中给出了每一层的 ID 的前 12 位。并且下载结束后,给出该镜像完整的 `sha256` 的摘要,以确保下载一致性。