非常教程

Docker 17参考手册

引擎 | Engine

apt-cacher-ng

注意

  • 如果您不喜欢 sudo,请参阅授予非 root 访问权限
  • 如果你通过 TCP 使用 macOS 或 docker,那么你不应该使用 sudo。

当你有多个 Docker 服务器,或者构建不能使用 Docker 构建缓存的不相关的 Docker 容器时,为你的包提供一个缓存代理会很有用。这个容器使得任何包的第二次下载几乎是即时的。

使用以下 Dockerfile:

#
# Build: docker build -t apt-cacher .
# Run: docker run -d -p 3142:3142 --name apt-cacher-run apt-cacher
#
# and then you can run containers with:
#   docker run -t -i --rm -e http_proxy http://dockerhost:3142/ debian bash
#
# Here, `dockerhost` is the IP address or FQDN of a host running the Docker daemon
# which acts as an APT proxy server.
FROM        ubuntu

VOLUME      ["/var/cache/apt-cacher-ng"]
RUN     apt-get update && apt-get install -y apt-cacher-ng

EXPOSE      3142
CMD     chmod 777 /var/cache/apt-cacher-ng && /etc/init.d/apt-cacher-ng start && tail -f /var/log/apt-cacher-ng/*

使用以下命令构建图像:

$ docker build -t eg_apt_cacher_ng .

然后运行它,将暴露的端口映射到主机上的端口

$ docker run -d -p 3142:3142 --name test_apt_cacher_ng eg_apt_cacher_ng

要查看tailed默认命令中的日志文件,可以使用:

$ docker logs -f test_apt_cacher_ng

要让您的基于 Debian 的容器使用代理,您有以下选项。请注意,您必须使用运行test_apt_cacher_ng容器的主机的 IP 地址或 FQDN 进行替换dockerhost

1. 添加一个 apt 代理设置 echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/conf.d/01proxy

2. 设置环境变量:http_proxy=http://dockerhost:3142/

3. 改变你的sources.list条目从http://dockerhost:3142/开始

4. 使用--link将基于 Debian 的容器链接到 APT 代理容器

5. 使用基于 Debian 的容器创建 APT 代理容器的自定义网络。

选项1将设置安全地注入本地通用基础版本的 apt 配置中:

FROM ubuntu
RUN  echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/apt.conf.d/01proxy
RUN apt-get update && apt-get install -y vim git

# docker build -t my_ubuntu .

选项2是不错的测试,但会破坏其他 HTTP 客户端,其服从http_proxy,比如curlwget和其他:

$ docker run --rm -t -i -e http_proxy=http://dockerhost:3142/ debian bash

选项3是最不便携的,但有时您可能需要这样做,并且您也可以从Dockerfile中选择。

选项4使用以下命令将 Debian 容器链接到代理服务器:

$ docker run -i -t --link test_apt_cacher_ng:apt_proxy -e http_proxy=http://apt_proxy:3142/ debian bash

选项5创建了一个 APT 代理服务器和基于 Debian 的容器的自定义网络:

$ docker network create mynetwork
$ docker run -d -p 3142:3142 --network=mynetwork --name test_apt_cacher_ng eg_apt_cacher_ng
$ docker run --rm -it --network=mynetwork -e http_proxy=http://test_apt_cacher_ng:3142/ debian bash

Apt-cacher-ng 有一些工具可以让您管理存储库,并且可以通过利用VOLUME指令和我们构建的用于运行服务的映像来使用它们:

$ docker run --rm -t -i --volumes-from test_apt_cacher_ng eg_apt_cacher_ng bash

root@f38c87f2a42d:/# /usr/lib/apt-cacher-ng/distkill.pl
Scanning /var/cache/apt-cacher-ng, please wait...
Found distributions:
bla, taggedcount: 0
     1. precise-security (36 index files)
     2. wheezy (25 index files)
     3. precise-updates (36 index files)
     4. precise (36 index files)
     5. wheezy-updates (18 index files)

Found architectures:
     6. amd64 (36 index files)
     7. i386 (24 index files)

WARNING: The removal action may wipe out whole directories containing
         index files. Select d to see detailed list.

(Number nn: tag distribution or architecture nn; 0: exit; d: show details; r: remove tagged; q: quit): q

最后,通过停止并取出容器,然后移除图像,在测试后清理。

$ docker stop test_apt_cacher_ng
$ docker rm test_apt_cacher_ng
$ docker rmi eg_apt_cacher_ng

docker, example, package installation, networking, debian, ubuntu

引擎 | Engine相关

1..NET核心应用程序(引擎) | .NET Core application (Engine)
2.关于图像,容器和存储驱动程序(引擎) | About images, containers, and storage drivers (Engine)
3.向swarm添加节点(Engine) | Add nodes to the swarm (Engine)
4.应用自定义元数据(引擎) | Apply custom metadata (Engine)
5.应用滚动更新(引擎) | Apply rolling updates (Engine)
6.编写Dockerfiles(引擎)的最佳实践 | Best practices for writing Dockerfiles (Engine)
7.二进制(引擎) | Binaries (Engine)
8.将容器端口绑定到主机(引擎) | Bind container ports to the host (Engine)
9.突破性变化(引擎) | Breaking changes (Engine)
10.建立自己的网桥 | Build your own bridge (Engine)
11.CentOS (Engine)
12.CentOS (Engine)
13.配置容器DNS(引擎) | Configure container DNS (Engine)
14.在用户定义的网络中配置容器DNS(引擎) | Configure container DNS in user-defined networks (Engine)
15.CouchDB (Engine)
16.创建基本映像(引擎) | Create a base image (Engine)
17.创建群(引擎) | Create a swarm (Engine)
18.自定义docker0网桥(引擎) | Customize the docker0 bridge (Engine)
19.Debian (Engine)
20.默认桥接网络 | Default bridge network
21.删除服务(引擎) | Delete the service (Engine)
22.部署服务(引擎) | Deploy a service (Engine)
23.将服务部署到一个群(引擎) | Deploy services to a swarm (Engine)
24.不推荐的引擎功能 | Deprecated Engine features
25.Docker容器网络(引擎) | Docker container networking (Engine)
26.Docker概述(引擎) | Docker overview (Engine)
27.Docker运行参考(引擎) | Docker run reference (Engine)
28.Dockerfile引用(引擎) | Dockerfile reference (Engine)
29.Dockerize应用程序 | Dockerize an application
30.排空节点(引擎) | Drain a node (Engine)
31.引擎 | Engine
32.FAQ(引擎) | FAQ (Engine)
33.Fedora (Engine)
34.开始 | Get started (Engine)
35.开始使用macvlan网络驱动程序 | Get started with macvlan network driver (Engine)
36.开始使用多主机网络 | Get started with multi-host networking (Engine)
37.节点如何工作 | How nodes work (Engine)
38.服务如何运作(引擎) | How services work (Engine)
39.图像管理 | Image management (Engine)
40.检查服务(引擎) | Inspect the service (Engine)
41.安装Docker(引擎) | Install Docker (Engine)
42.IPv6与Docker(引擎) | IPv6 with Docker (Engine)
43.将节点加入群集(引擎) | Join nodes to a swarm (Engine)
44.旧容器链接(引擎) | Legacy container links (Engine)
45.锁定你的群(引擎) | Lock your swarm (Engine)
46.管理群中的节点(引擎) | Manage nodes in a swarm (Engine)
47.使用Docker机密管理敏感数据(引擎) | Manage sensitive data with Docker secrets (Engine)
48.使用PKI管理swarm安全性(引擎) | Manage swarm security with PKI (Engine)
49.管理群体服务网络(引擎) | Manage swarm service networks (Engine)
50.迁移到引擎1.10 | Migrate to Engine 1.10
51.可选的Linux安装后步骤(引擎) | Optional Linux post-installation steps (Engine)
52.总览 | Overview (Engine)
53.总览 | Overview (Engine)
54.PostgreSQL(引擎) | PostgreSQL (Engine)
55.群集模式中的筏共识(引擎) | Raft consensus in swarm mode (Engine)
56.Riak (Engine)
57.以群集模式运行Docker Engine | Run Docker Engine in swarm mode
58.扩展服务(引擎) | Scale the service (Engine)
59.SDKs (Engine)
60.选择一个存储驱动 | Select a storage driver (Engine)
61.设置教程(引擎) | Set up for the tutorial (Engine)
62.SSHd (Engine)
63.存储驱动总览 | Storage driver overview (Engine)
64.存储服务配置数据(引擎) | Store service configuration data (Engine)
65.Swarm管理指南(引擎) | Swarm administration guide (Engine)
66.Swarm模式关键概念(引擎) | Swarm mode key concepts (Engine)
67.Swarm模式覆盖网络安全模型(引擎) | Swarm mode overlay network security model (Engine)
68.群模式概述(引擎) | Swarm mode overview (Engine)
69.Ubuntu (Engine)
70.Ubuntu (Engine)
71.了解容器通信(引擎) | Understand container communication (Engine)
72.使用多阶段构建(引擎) | Use multi-stage builds (Engine)
73.使用swarm模式路由网格(引擎) | Use swarm mode routing mesh (Engine)
74.使用AUFS存储驱动程序(引擎) | Use the AUFS storage driver (Engine)
75.使用Btrfs存储驱动程序(引擎) | Use the Btrfs storage driver (Engine)
76.使用设备映射器存储驱动程序(引擎) | Use the Device mapper storage driver (Engine)
77.使用OverlayFS存储驱动程序(引擎) | Use the OverlayFS storage driver (Engine)
78.使用VFS存储驱动程序(引擎) | Use the VFS storage driver (Engine)
79.使用ZFS存储驱动程序(引擎) | Use the ZFS storage driver (Engine)
80.处理图像 | Work with images
81.使用网络命令(引擎) | Work with network commands (Engine)
Docker 17

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

主页 https://docker.com/
源码 https://github.com/docker/docker
版本 17
发布版本 17.06