非常教程

Docker 17参考手册

引擎 | Engine

PostgreSQL(引擎) | PostgreSQL (Engine)

在Docker上安装PostgreSQL

假设没有符合您需要的码头形象码头枢纽,你可以自己创造一个。

首先创建一个新的Dockerfile*

这个PostgreSQL设置只用于开发目的。请参考PostgreSQL文档来微调这些设置,使其具有适当的安全性。

#
# example Dockerfile for https://docs.docker.com/examples/postgresql_service/
#

FROM ubuntu

# Add the PostgreSQL PGP key to verify their Debian packages.
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8

# Add PostgreSQL's repository. It contains the most recent stable release
#     of PostgreSQL, ``9.3``.
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list

# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3
#  There are some warnings (in red) that show up during the build. You can hide
#  them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3

# Note: The official Debian and Ubuntu images automatically ``apt-get clean``
# after each ``apt-get``

# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed``
USER postgres

# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and
# then create a database `docker` owned by the ``docker`` role.
# Note: here we use ``&&\`` to run commands one after the other - the ``\``
#       allows the RUN command to span multiple lines.
RUN    /etc/init.d/postgresql start &&\
    psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\
    createdb -O docker docker

# Adjust PostgreSQL configuration so that remote connections to the
# database are possible.
RUN echo "host all  all    0.0.0.0/0  md5" >> /etc/postgresql/9.3/main/pg_hba.conf

# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf``
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf

# Expose the PostgreSQL port
EXPOSE 5432

# Add VOLUMEs to allow backup of config, logs and databases
VOLUME  ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]

# Set the default command to run when starting the container
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]

从Dockerfile构建一个图像,为它指定一个名称。

$ docker build -t eg_postgresql .

在前台%29中运行PostgreSQL服务器容器%28:

$ docker run --rm -P --name pg_test eg_postgresql

有两种连接PostgreSQL服务器的方法。我们可以用链接容器,或者我们可以从主机%28或网络%29访问它。

*--rm在容器成功退出时移除容器及其图像。

使用容器链接

容器可以直接链接到另一个容器的港口-link remote_name:local_alias在客户的docker run这将设置一些环境变量,然后可用于连接:

$ docker run --rm -t -i --link pg_test:pg eg_postgresql bash

postgres@7ef98b1b7243:/$ psql -h $PG_PORT_5432_TCP_ADDR -p $PG_PORT_5432_TCP_PORT -d docker -U docker --password

从您的主机系统连接

假设安装了PostgreSQLClient,也可以使用主机映射端口进行测试。你需要用docker ps要了解容器首先映射到哪个本地主机端口:

$ docker ps

CONTAINER ID        IMAGE                  COMMAND                CREATED             STATUS              PORTS                                      NAMES
5e24362f27f6        eg_postgresql:latest   /usr/lib/postgresql/   About an hour ago   Up About an hour    0.0.0.0:49153->5432/tcp                    pg_test

$ psql -h localhost -p 49153 -d docker -U docker --password

测试数据库

一旦您通过身份验证并拥有docker =#提示,您可以创建一个表并填充它。

psql (9.3.1)
Type "help" for help.

$ docker=# CREATE TABLE cities (
docker(#     name            varchar(80),
docker(#     location        point
docker(# );
CREATE TABLE
$ docker=# INSERT INTO cities VALUES ('San Francisco', '(-194.0, 53.0)');
INSERT 0 1
$ docker=# select * from cities;
     name      | location
---------------+-----------
 San Francisco | (-194,53)
(1 row)

使用容器卷

可以使用定义的卷检查PostgreSQL日志文件,并备份配置和数据:

$ docker run --rm --volumes-from pg_test -t -i busybox sh

/ # ls
bin      etc      lib      linuxrc  mnt      proc     run      sys      usr
dev      home     lib64    media    opt      root     sbin     tmp      var
/ # ls /etc/postgresql/9.3/main/
environment      pg_hba.conf      postgresql.conf
pg_ctl.conf      pg_ident.conf    start.conf
/tmp # ls /var/log
ldconfig    postgresql

docker,示例,软件包安装,postgresql

引擎 | 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.apt-cacher-ng
7.编写Dockerfiles(引擎)的最佳实践 | Best practices for writing Dockerfiles (Engine)
8.二进制(引擎) | Binaries (Engine)
9.将容器端口绑定到主机(引擎) | Bind container ports to the host (Engine)
10.突破性变化(引擎) | Breaking changes (Engine)
11.建立自己的网桥 | Build your own bridge (Engine)
12.CentOS (Engine)
13.CentOS (Engine)
14.配置容器DNS(引擎) | Configure container DNS (Engine)
15.在用户定义的网络中配置容器DNS(引擎) | Configure container DNS in user-defined networks (Engine)
16.CouchDB (Engine)
17.创建基本映像(引擎) | Create a base image (Engine)
18.创建群(引擎) | Create a swarm (Engine)
19.自定义docker0网桥(引擎) | Customize the docker0 bridge (Engine)
20.Debian (Engine)
21.默认桥接网络 | Default bridge network
22.删除服务(引擎) | Delete the service (Engine)
23.部署服务(引擎) | Deploy a service (Engine)
24.将服务部署到一个群(引擎) | Deploy services to a swarm (Engine)
25.不推荐的引擎功能 | Deprecated Engine features
26.Docker容器网络(引擎) | Docker container networking (Engine)
27.Docker概述(引擎) | Docker overview (Engine)
28.Docker运行参考(引擎) | Docker run reference (Engine)
29.Dockerfile引用(引擎) | Dockerfile reference (Engine)
30.Dockerize应用程序 | Dockerize an application
31.排空节点(引擎) | Drain a node (Engine)
32.引擎 | Engine
33.FAQ(引擎) | FAQ (Engine)
34.Fedora (Engine)
35.开始 | Get started (Engine)
36.开始使用macvlan网络驱动程序 | Get started with macvlan network driver (Engine)
37.开始使用多主机网络 | Get started with multi-host networking (Engine)
38.节点如何工作 | How nodes work (Engine)
39.服务如何运作(引擎) | How services work (Engine)
40.图像管理 | Image management (Engine)
41.检查服务(引擎) | Inspect the service (Engine)
42.安装Docker(引擎) | Install Docker (Engine)
43.IPv6与Docker(引擎) | IPv6 with Docker (Engine)
44.将节点加入群集(引擎) | Join nodes to a swarm (Engine)
45.旧容器链接(引擎) | Legacy container links (Engine)
46.锁定你的群(引擎) | Lock your swarm (Engine)
47.管理群中的节点(引擎) | Manage nodes in a swarm (Engine)
48.使用Docker机密管理敏感数据(引擎) | Manage sensitive data with Docker secrets (Engine)
49.使用PKI管理swarm安全性(引擎) | Manage swarm security with PKI (Engine)
50.管理群体服务网络(引擎) | Manage swarm service networks (Engine)
51.迁移到引擎1.10 | Migrate to Engine 1.10
52.可选的Linux安装后步骤(引擎) | Optional Linux post-installation steps (Engine)
53.总览 | Overview (Engine)
54.总览 | Overview (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