1. 测试

root@iZ232ngsvp8Z:~# docker run hello-world

 

Hello from Docker.

This message shows that your installationappears to be working correctly.

 

To generate this message, Docker took thefollowing steps:

 1.The Docker client contacted the Docker daemon.

 2.The Docker daemon pulled the "hello-world" image from the Docker Hub.

 3.The Docker daemon created a new container from that image which runs the

   executable that produces the output you are currently reading.

 4.The Docker daemon streamed that output to the Docker client, which sent it

   to your terminal.

 

To try something more ambitious, you canrun an Ubuntu container with:

 $docker run -it ubuntu bash

 

Share images, automate workflows, and morewith a free Docker Hub account:

 https://hub.docker.com

 

For more examples and ideas, visit:

 https://docs.docker.com/userguide/

 

 

 

2. 源码地址

https://github.com/docker/docker

源码地址

 

3. 安装

https://docs.docker.com/installation/ubuntulinux/

 

which curl
 install curl
#Get the latest Docker package.
curl -sSL https://get.docker.com/ | sh

 

4. 命令

http://www.open-open.com/lib/view/open1410568733492.html

 

docker run -i -t ubuntu /bin/bash #创建一个容器,-t是临时终端

 

docker run -i -t ubuntu /bin/bash #此方式运行的容器,退出后容器就会关闭

 

启动ssh,容器以后台方式运行

    docker run -d -p 50001:22 <容器id> /usr/sbin/sshd-D  
    #容器id可通过 docker ps-a查看,最上面的为最新

 

 

服务安装完成后,停止容器。

    docker stop <容器id> #停止运行的容器

 

 

5. 虚拟机与Docker差异

http://www.open-open.com/news/view/16e39b5

 

下面这张图描述了虚拟机和Docker之间的差异。VM中,宿主OS上是 hypervisor(虚拟机监视器),最上层是客户机操作系统,而Docker则使用 Docker引擎和容器。这样解释你能理解吗? Docker引擎和hypervisor之间的区别又是什么呢?你可以列出运行在宿主OS上的进程来理解它们的区别。 


 

Docker 概念及相互作用

·                               主机,运行容器的机器。

·                               镜像,文件的层次结构,以及包含如何运行容器的元数据

·                               容器,一个从镜像中启动,包含正在运行的程序的进程

·                               Registry镜像仓库

·                               卷,容器外的存储

·                               Dockerfile用于创建镜像的脚本

 

 

镜像

镜像是一种文件结构,包含如何运行容器的元数据。Dockerfile中的每条命令都会在文件系统中创建一个新的层次结构,文件系统在这些层次上构建起来,镜像就构建于这些联合的文件系统之上。

 

 

Commands for interacting with images
$ docker images  # 查看所有镜像.
$ docker import  # tarball创建镜像
$ docker build   # 通过Dockerfile创建镜像
$ docker commit  # 从容器中创建镜像
$ docker rmi     # 删除镜像
$ docker history # 列出镜像的变更历史

 

 6.测试

root@iZ232ngsvp8Z:~#docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

ubuntu              latest              8251da35e7a7        10 days ago         188.4 MB

hello-world         latest              af340544ed62        11 days ago         960 B

 

root@iZ232ngsvp8Z:~#docker history ubuntu

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

8251da35e7a7        10 days ago         /bin/sh -c #(nop) CMD["/bin/bash"]             0B                

e5855facec0b        10 days ago         /bin/sh -c sed -i's/^#\s*\(deb.*universe\)$/   1.895kB           

5bff21ba5409        10 days ago         /bin/sh -c echo '#!/bin/sh' >/usr/sbin/polic   194.5 kB           

6071b4945dcf        10 days ago         /bin/sh -c #(nop) ADDfile:8c057200590b935e07   188.2 MB

 

root@iZ232ngsvp8Z:~#docker history hello-world

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

af340544ed62        11 days ago         /bin/sh -c #(nop) CMD["/hello"]                0B                

535020c3e8ad        11 days ago         /bin/sh -c #(nop) COPYfile:4abd3bff60458ca3b   960 B  

 

root@iZ232ngsvp8Z:~#docker create ubuntu

313fffb3a7ca996b64e263eb611f409735b89ed4d2f1a5e541804e4d7e55524f

root@iZ232ngsvp8Z:~#docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES

313fffb3a7ca        ubuntu              "/bin/bash"         28 seconds ago      Created                                        focused_bell

 

 

docker  rm ed7fa2d56648  删除容器

 

docker  start   b85e40d1dbfa 启动容器

docker  attach  b85e40d1dbfa  进入容器

 

 

 

root@iZ232ngsvp8Z:~#docker  attach b85e40d1dbfa

root@b85e40d1dbfa:/#

root@b85e40d1dbfa:/#ll

total 76

drwxr-xr-x  34 root root 4096 Aug 18 16:31 ./

drwxr-xr-x  34 root root 4096 Aug 18 16:31 ../

-rwxr-xr-x   1 root root    0 Aug 18 16:23 .dockerenv*

-rwxr-xr-x   1 root root    0 Aug 18 16:23 .dockerinit*

drwxr-xr-x   2 root root 4096 Aug  6 03:33 bin/

drwxr-xr-x   2 root root 4096 Apr 10  2014 boot/

drwxr-xr-x   5 root root  380 Aug 18 16:31 dev/

drwxr-xr-x  64 root root 4096 Aug 18 16:23 etc/

drwxr-xr-x   2 root root 4096 Apr 10  2014 home/

drwxr-xr-x  12 root root 4096 Aug  6 03:33 lib/

drwxr-xr-x   2 root root 4096 Aug  6 03:33 lib64/

drwxr-xr-x   2 root root 4096 Aug  6 03:33 media/

drwxr-xr-x   2 root root 4096 Apr 10  2014 mnt/

drwxr-xr-x   2 root root 4096 Aug  6 03:33 opt/

dr-xr-xr-x 121 rootroot    0 Aug 18 16:31 proc/

drwx------   2 root root 4096 Aug 18 16:24 root/

drwxr-xr-x   7 root root 4096 Aug  6 03:33 run/

drwxr-xr-x   2 root root 4096 Aug  7 22:16 sbin/

drwxr-xr-x   2 root root 4096 Aug  6 03:33 srv/

dr-xr-xr-x  13 root root    0 Aug 18 16:31 sys/

drwxr-xr-x   2 root root 4096 Aug 18 16:24 test1/

drwxrwxrwt   2 root root 4096 Aug  6 03:33 tmp/

drwxr-xr-x  11 root root 4096 Aug  7 22:16 usr/

drwxr-xr-x  12 root root 4096 Aug  7 22:16 var/

root@b85e40d1dbfa:/#ifconfig

eth0      Link encap:Ethernet  HWaddr 02:42:c0:a8:2a:05 

          inet addr:192.168.42.5  Bcast:0.0.0.0  Mask:255.255.255.0

          inet6 addr:fe80::42:c0ff:fea8:2a05/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1

          RX packets:0 errors:0 dropped:0overruns:0 frame:0

          TX packets:8 errors:0 dropped:0overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:648 (648.0 B)

 

lo        Link encap:Local Loopback 

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:65536 Metric:1

          RX packets:0 errors:0 dropped:0overruns:0 frame:0

          TX packets:0 errors:0 dropped:0overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

 

root@iZ232ngsvp8Z:~#docker  start c52cf047e34b

c52cf047e34b

root@iZ232ngsvp8Z:~#docker  attach c52cf047e34b

root@c52cf047e34b:/#

root@c52cf047e34b:/#

root@c52cf047e34b:/#

root@c52cf047e34b:/#ll

total 72

drwxr-xr-x  33 root root 4096 Aug 18 16:32 ./

drwxr-xr-x  33 root root 4096 Aug 18 16:32 ../

-rwxr-xr-x   1 root root    0 Aug 18 16:24 .dockerenv*

-rwxr-xr-x   1 root root    0 Aug 18 16:24 .dockerinit*

drwxr-xr-x   2 root root 4096 Aug  6 03:33 bin/

drwxr-xr-x   2 root root 4096 Apr 10  2014 boot/

drwxr-xr-x   5 root root 380 Aug 18 16:32 dev/

drwxr-xr-x  64 root root 4096 Aug 18 16:24 etc/

drwxr-xr-x   2 root root 4096 Apr 10  2014 home/

drwxr-xr-x  12 root root 4096 Aug  6 03:33 lib/

drwxr-xr-x   2 root root 4096 Aug  6 03:33 lib64/

drwxr-xr-x   2 root root 4096 Aug  6 03:33 media/

drwxr-xr-x   2 root root 4096 Apr 10  2014 mnt/

drwxr-xr-x   2 root root 4096 Aug  6 03:33 opt/

dr-xr-xr-x 121 rootroot    0 Aug 18 16:32 proc/

drwx------   2 root root 4096 Aug 18 16:24 root/

drwxr-xr-x   7 root root 4096 Aug  6 03:33 run/

drwxr-xr-x   2 root root 4096 Aug  7 22:16 sbin/

drwxr-xr-x   2 root root 4096 Aug  6 03:33 srv/

dr-xr-xr-x  13 root root    0 Aug 18 16:32 sys/

drwxrwxrwt   2 root root 4096 Aug  6 03:33 tmp/

drwxr-xr-x  11 root root 4096 Aug  7 22:16 usr/

drwxr-xr-x  12 root root 4096 Aug  7 22:16 var/

root@c52cf047e34b:/#ifconfig

eth0      Link encap:Ethernet  HWaddr 02:42:c0:a8:2a:06 

          inet addr:192.168.42.6  Bcast:0.0.0.0  Mask:255.255.255.0

          inet6 addr:fe80::42:c0ff:fea8:2a06/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1

          RX packets:0 errors:0 dropped:0overruns:0 frame:0

          TX packets:8 errors:0 dropped:0overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:648 (648.0 B)

 

lo        Link encap:Local Loopback 

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:65536 Metric:1

          RX packets:0 errors:0 dropped:0overruns:0 frame:0

          TX packets:0 errors:0 dropped:0overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

 

 

root@iZ232ngsvp8Z:~#docker  ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES

c52cf047e34b        ubuntu              "/bin/bash"         10 minutes ago      Exited (0) 37 seconds ago                       sick_tesla

b85e40d1dbfa        ubuntu              "/bin/bash"         11 minutes ago      Exited (0) 2 minutes ago                        trusting_poitras

0f699f850631        ubuntu              "/bin/bash"         14 minutes ago      Exited (0) 14 minutes ago                       evil_bohr

b65260158cda        ubuntu              "/bin/bash"         14 minutes ago      Exited (0) 14 minutes ago                       goofy_heisenberg

f9edf202c967        hello-world         "/hello"            39 minutes ago      Exited (0) 39 minutes ago                       furious_bhabha

218cae3a7c80        ubuntu              "/bin/bash"         40 minutes ago      Exited (0) 39 minutes ago                       stoic_mestorf

fda911eaffbd        hello-world         "/hello"            42 minutes ago      Exited (0) 42 minutes ago                       compassionate_noyce

85e83c099417        hello-world         "/hello"            43 minutes ago      Exited (0) 43 minutes ago                       mad_panini

68e9124ed0b9        hello-world         "/hello"            16 hours ago        Exited (0) 16 hours ago                         clever_lalande

b6de6337737c        hello-world         "/hello"            16 hours ago        Exited (0) 16 hours ago                         sleepy_engelbart

 

 

 

7.  容器互联

http://www.open-open.com/doc/view/bf6f3ac591ce40e8808b52b7ea877375

 

8. Docker 底层技术

http://dockerpool.com/static/books/docker_practice/underly/README.html

Docker 底层的核心技术包括 Linux 上的名字空间(Namespaces)、控制组(Control groups)、Union 文件系统(Union file systems)和容器格式(Container format)。

我们知道,传统的虚拟机通过在宿主主机中运行 hypervisor 来模拟一整套完整的硬件环境提供给虚拟机的操作系统。虚拟机系统看到的环境是可限制的,也是彼此隔离的。这种直接的做法实现了对资源最完整的封装,但很多时候往往意味着系统资源的浪费。例如,以宿主机和虚拟机系统都为 Linux 系统为例,虚拟机中运行的应用其实可以利用宿主机系统中的运行环境。

我们知道,在操作系统中,包括内核、文件系统、网络、PID、UID、IPC、内存、硬盘、CPU 等等,所有的资源都是应用进程直接共享的。要想实现虚拟化,除了要实现对内存、CPU、网络IO、硬盘IO、存储空间等的限制外,还要实现文件系统、网络、PID、UID、IPC等等的相互隔离。前者相对容易实现一些,后者则需要宿主机系统的深入支持。

随着 Linux 系统对于名字空间功能的完善实现,程序员已经可以实现上面的所有需求,让某些进程在彼此隔离的名字空间中运行。大家虽然都共用一个内核和某些运行时环境(例如一些系统命令和系统库),但是彼此却看不到,都以为系统中只有自己的存在。这种机制就是容器(Container),利用名字空间来做权限的隔离控制,利用 cgroups 来做资源分配。

 

9.网络

http://dockerpool.com/static/books/docker_practice/underly/network.html

 

10. postgres

https://hub.docker.com/_/postgres/

 

11.为什么用docker

http://www.open-open.com/doc/view/c849589896704388964b04be88f88637

docker是容器的一种,与虚拟机的区别?见该链接

 

12.  系统支持


 

13. 检查docker 安装是否正常

root@iZ232ngsvp8Z:~#docker info

Containers: 10

Images: 6

Storage Driver:aufs

 Root Dir: /var/lib/docker/aufs

 Backing Filesystem: extfs

 Dirs: 26

 Dirperm1 Supported: false

Execution Driver:native-0.2

Logging Driver:json-file

Kernel Version: 3.13.0-32-generic

Operating System:Ubuntu 14.04.2 LTS

CPUs: 1

Total Memory: 992.5MiB

Name: iZ232ngsvp8Z

ID:XDVV:5BQ4:RKZP:727E:PZJS:H54V:BSSG:IINI:ZPWM:2TCB:7O3Y:UT66

WARNING: No swap limitsupport

root@iZ232ngsvp8Z:~#

 

 

14.测试

https://hub.docker.com/_/postgres/

 

root@iZ232ngsvp8Z:~#docker  images

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

ubuntu              latest              8251da35e7a7        11 days ago         188.4 MB

hello-world         latest              af340544ed62        11 days ago         960 B

postgres            latest              730d1d72bda2        3 weeks ago         265.3 MB

root@iZ232ngsvp8Z:~#docker  ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES

291d3506079f        postgres           "/docker-entrypoint.s"  3 minutes ago       Up 3minutes                  5432/tcp            postgres1

80c759a286cb        postgres           "/docker-entrypoint.s"  10 minutes ago      Up 4 minutes                  5432/tcp            some-app

c30cdc916ca0        postgres            "/docker-entrypoint.s"   11 minutes ago      Up 4 minutes                  5432/tcp            some-postgres

c52cf047e34b        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            sick_tesla

b85e40d1dbfa        ubuntu              "/bin/bash"              7 hours ago         Exited (137) 26 minutes ago                       trusting_poitras

0f699f850631        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            evil_bohr

b65260158cda        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            goofy_heisenberg

f9edf202c967        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            furious_bhabha

218cae3a7c80        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            stoic_mestorf

fda911eaffbd        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            compassionate_noyce

85e83c099417        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            mad_panini

68e9124ed0b9        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           clever_lalande

b6de6337737c        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           sleepy_engelbart

 

 

 

15. 测试

root@iZ232ngsvp8Z:~#docker -d

Warning: '-d' isdeprecated, it will be removed soon. See usage.

WARN[0000] pleaseuse 'docker daemon' instead.         

INFO[0000]Listening for HTTP on unix (/var/run/docker.sock)

INFO[0000][graphdriver] using prior storage driver "aufs"

INFO[0000] OptionDefaultDriver: bridge                

INFO[0000] OptionDefaultNetwork: bridge               

WARN[0000] Runningmodprobe bridge nf_nat br_netfilter failed with message: modprobe: WARNING:Module br_netfilter not found.

, error: exitstatus 1

INFO[0000]Firewalld running: false                    

WARN[0000] Yourkernel does not support swap memory limit.

INFO[0000] Loadingcontainers: start.                  

....................

INFO[0000] Loadingcontainers: done.                   

INFO[0000] Daemonhas completed initialization         

INFO[0000] Dockerdaemon                                commit=d12ea79 execdriver=native-0.2 graphdriver=aufs version=1.8.1

 

 

 

INFO[0013] GET/v1.20/images/json                      

 

  

 

INFO[0059] POST/v1.20/containers/create               

INFO[0059] POST/v1.20/containers/b85e40d1dbfaaa7779babd00a07125321ca0ccaa6fd086888a45ca6d45badb2b/attach?stderr=1&stdin=1&stdout=1&stream=1

INFO[0059] POST/v1.20/containers/b85e40d1dbfaaa7779babd00a07125321ca0ccaa6fd086888a45ca6d45badb2b/start

INFO[0059] POST/v1.20/containers/b85e40d1dbfaaa7779babd00a07125321ca0ccaa6fd086888a45ca6d45badb2b/resize?h=45&w=167

INFO[0084] GET/v1.20/containers/b85e40d1dbfaaa7779babd00a07125321ca0ccaa6fd086888a45ca6d45badb2b/json

INFO[0098] POST/v1.20/containers/create               

INFO[0099] POST/v1.20/containers/c52cf047e34b83def93f8c24512536b07778cfe802caaba61e5dd251b4c91428/attach?stderr=1&stdin=1&stdout=1&stream=1

INFO[0099] POST/v1.20/containers/c52cf047e34b83def93f8c24512536b07778cfe802caaba61e5dd251b4c91428/start

INFO[0099] POST/v1.20/containers/c52cf047e34b83def93f8c24512536b07778cfe802caaba61e5dd251b4c91428/resize?h=45&w=167

INFO[0106] GET/v1.20/containers/c52cf047e34b83def93f8c24512536b07778cfe802caaba61e5dd251b4c91428/json

INFO[0119] GET/v1.20/containers/json?all=1            

 

Welcome to Ubuntu 14.04.2LTS (GNU/Linux 3.13.0-32-generic x86_64)

 

 * Documentation:  https://help.ubuntu.com/

 

Welcome to aliyunElastic Compute Service!

 

Last login: Wed Aug19 07:19:09 2015 from 123.139.17.249

root@iZ232ngsvp8Z:~#docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -dpostgres

Unable to findimage 'postgres:latest' locally

latest: Pullingfrom library/postgres

 

902b87aaaec9: Pullcomplete

9a61b6b1315e: Pullcomplete

26a84c436db4: Pullcomplete

22ed955cce18: Pullcomplete

8b6b2a3b7f9c: Pullcomplete

c783ebe7a1d4: Pullcomplete

e07b5a739ed9: Pullcomplete

0b82f508e063: Pullcomplete

02fa71f1fa38: Pullcomplete

b41b53da5fba: Pullcomplete

49915906faae: Pullcomplete

a814508841fa: Pullcomplete

64957633c267: Pullcomplete

a95070c23e86: Pullcomplete

c5d75e7f9094: Pullcomplete

3fa84fbfdec9: Pullcomplete

39172f8b90f2: Pullcomplete

09e02a9f8afe: Pullcomplete

4df8a54cf33a: Pullcomplete

3e840dbb5474: Pullcomplete

730d1d72bda2:Already exists

library/postgres:latest:The image you are pulling has been verified. Important: image verification is atech preview feature and should not be relied on to provide security.

 

Digest:sha256:66ba100bc635be1746daadd3ecfa46b51fbb767cd9fbc170edbf33483010065b

Status: Downloadednewer image for postgres:latest

c30cdc916ca093d956082d8a7981a12aef59953b6c3d313088e62ff65f23ba09

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

ubuntu              latest              8251da35e7a7        11 days ago         188.4 MB

hello-world         latest              af340544ed62        11 days ago         960 B

postgres            latest              730d1d72bda2        3 weeks ago         265.3 MB

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker run --name some-app --link some-postgres:postgres -d postgres

80c759a286cb294674ebe2432b37f99c95c8a79bf5bb9fbf619d1ce78230e2bc

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker  ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                        PORTS               NAMES

80c759a286cb        postgres           "/docker-entrypoint.s"  21 seconds ago       Up 20 seconds                 5432/tcp            some-app

c30cdc916ca0        postgres           "/docker-entrypoint.s"  About a minute ago   Up About aminute             5432/tcp            some-postgres

c52cf047e34b        ubuntu              "/bin/bash"              7 hours ago          Exited (0) 7 hours ago                            sick_tesla

b85e40d1dbfa        ubuntu              "/bin/bash"              7 hours ago          Exited (137) 16 minutes ago                       trusting_poitras

0f699f850631        ubuntu              "/bin/bash"              7 hours ago          Exited (0) 7 hours ago                            evil_bohr

b65260158cda        ubuntu              "/bin/bash"              7 hours ago          Exited (0) 7 hours ago                            goofy_heisenberg

f9edf202c967        hello-world         "/hello"                 7 hours ago          Exited (0) 7 hours ago                            furious_bhabha

218cae3a7c80        ubuntu              "/bin/bash"              7 hours ago          Exited (0) 7 hours ago                            stoic_mestorf

fda911eaffbd        hello-world         "/hello"                 7 hours ago          Exited (0) 7 hours ago                            compassionate_noyce

85e83c099417        hello-world         "/hello"                 7 hours ago          Exited (0) 7 hours ago                            mad_panini

68e9124ed0b9        hello-world         "/hello"                 23 hours ago         Exited (0) 23 hours ago                           clever_lalande

b6de6337737c        hello-world         "/hello"                 23 hours ago         Exited (0) 23 hours ago                           sleepy_engelbart

root@iZ232ngsvp8Z:~#docker attach 80c759a286cb

 

 

 

 

 

 

 

 

 

 

^CLOG:  received fast shutdown request

LOG:  aborting any active transactions

LOG:  autovacuum launcher shutting down

LOG:  shutting down

LOG:  database system is shut down

root@iZ232ngsvp8Z:~#docker attach 80c759a286cb

You cannot attachto a stopped container, start it first

root@iZ232ngsvp8Z:~#docker start 80c759a286cb

80c759a286cb

root@iZ232ngsvp8Z:~#docker attach 80c759a286cb

  

^CLOG:  received fast shutdown request

LOG:  aborting any active transactions

LOG:  autovacuum launcher shutting down

LOG:  shutting down

LOG:  database system is shut down

root@iZ232ngsvp8Z:~#docker attach 80c759a286cb

You cannot attachto a stopped container, start it first

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker start 80c759a286cb

80c759a286cb

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker  ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES

80c759a286cb        postgres           "/docker-entrypoint.s"  2 minutes ago       Up 6 seconds                  5432/tcp            some-app

c30cdc916ca0        postgres           "/docker-entrypoint.s"  3 minutes ago       Up 3 minutes                  5432/tcp            some-postgres

c52cf047e34b        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            sick_tesla

b85e40d1dbfa        ubuntu              "/bin/bash"              7 hours ago         Exited (137) 18 minutes ago                       trusting_poitras

0f699f850631        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            evil_bohr

b65260158cda        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            goofy_heisenberg

f9edf202c967        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            furious_bhabha

218cae3a7c80        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            stoic_mestorf

fda911eaffbd        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            compassionate_noyce

85e83c099417        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            mad_panini

68e9124ed0b9        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           clever_lalande

b6de6337737c        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           sleepy_engelbart

root@iZ232ngsvp8Z:~#psql

The program 'psql'can be found in the following packages:

 * postgresql-client-common

 * postgres-xc-client

Try: apt-getinstall <selected package>

root@iZ232ngsvp8Z:~#docker run -it --link some-postgres:postgres --rm postgres sh -c 'exec psql -h"$POSTGRES_PORT_5432_TCP_ADDR" -p"$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

 

Password for userpostgres:

psql: FATAL:  password authentication failed for user"postgres"

root@iZ232ngsvp8Z:~#docker run -it --link some-postgres:postgres --rm postgres sh -c 'exec psql -h"$POSTGRES_PORT_5432_TCP_ADDR" -p"$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

Password for userpostgres:

psql: FATAL:  password authentication failed for user"postgres"

root@iZ232ngsvp8Z:~#docker run -it --link some-postgres:postgres --rm postgres sh -c 'exec psql -h"$POSTGRES_PORT_5432_TCP_ADDR" -p"$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

Password for userpostgres:

psql (9.4.4)

Type"help" for help.

 

postgres=# \d

No relations found.

postgres=# select1+1;

 ?column?

----------

        2

(1 row)

 

postgres=# \dq

Invalid command\dq. Try \? for help.

postgres=# \q

root@iZ232ngsvp8Z:~#docker  ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES

80c759a286cb        postgres           "/docker-entrypoint.s"  4 minutes ago       Up About aminute             5432/tcp            some-app

c30cdc916ca0        postgres           "/docker-entrypoint.s"  5 minutes ago       Up 5 minutes                  5432/tcp            some-postgres

c52cf047e34b        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            sick_tesla

b85e40d1dbfa        ubuntu              "/bin/bash"              7 hours ago         Exited (137) 20 minutes ago                       trusting_poitras

0f699f850631        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            evil_bohr

b65260158cda        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            goofy_heisenberg

f9edf202c967        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            furious_bhabha

218cae3a7c80        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            stoic_mestorf

fda911eaffbd        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            compassionate_noyce

85e83c099417        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            mad_panini

68e9124ed0b9        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           clever_lalande

b6de6337737c        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           sleepy_engelbart

root@iZ232ngsvp8Z:~#docker stop c30cdc916ca0

c30cdc916ca0

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker stop 80c759a286cb

80c759a286cb

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker run -it --link some-postgres:postgres --rm postgres sh -c 'exec psql -h"$POSTGRES_PORT_5432_TCP_ADDR" -p"$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

Error response fromdaemon: Cannot start container1ce92ae87ea303ca62d4847b70ef4c328dda46371810e40685541ce0afefc690: Cannot linkto a non running container: /some-postgres AS /serene_chandrasekhar/postgres

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

ubuntu              latest              8251da35e7a7        11 days ago         188.4 MB

hello-world         latest              af340544ed62        11 days ago         960 B

postgres            latest              730d1d72bda2        3 weeks ago         265.3 MB

root@iZ232ngsvp8Z:~#docker  ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES

80c759a286cb        postgres           "/docker-entrypoint.s"  5 minutes ago       Exited (0) 35seconds ago                        some-app

c30cdc916ca0        postgres           "/docker-entrypoint.s"  6 minutes ago       Exited (0) 43seconds ago                        some-postgres

c52cf047e34b        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            sick_tesla

b85e40d1dbfa        ubuntu              "/bin/bash"              7 hours ago         Exited (137) 21 minutes ago                       trusting_poitras

0f699f850631        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            evil_bohr

b65260158cda        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            goofy_heisenberg

f9edf202c967        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            furious_bhabha

218cae3a7c80        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            stoic_mestorf

fda911eaffbd        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            compassionate_noyce

85e83c099417        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            mad_panini

68e9124ed0b9        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           clever_lalande

b6de6337737c        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           sleepy_engelbart

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker  ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES

80c759a286cb        postgres           "/docker-entrypoint.s"  5 minutes ago       Exited (0) 37seconds ago                        some-app

c30cdc916ca0        postgres           "/docker-entrypoint.s"  6 minutes ago       Exited (0) 45seconds ago                        some-postgres

c52cf047e34b        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            sick_tesla

b85e40d1dbfa        ubuntu              "/bin/bash"              7 hours ago         Exited (137) 21 minutes ago                       trusting_poitras

0f699f850631        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            evil_bohr

b65260158cda        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            goofy_heisenberg

f9edf202c967        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            furious_bhabha

218cae3a7c80        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            stoic_mestorf

fda911eaffbd        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            compassionate_noyce

85e83c099417        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            mad_panini

68e9124ed0b9        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           clever_lalande

b6de6337737c        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           sleepy_engelbart

root@iZ232ngsvp8Z:~#docker start 80c759a286cb

Error response fromdaemon: Cannot start container 80c759a286cb: Cannot link to a non runningcontainer: /some-postgres AS /some-app/postgres

Error: failed tostart containers: [80c759a286cb]

root@iZ232ngsvp8Z:~#docker start c30cdc916ca0

c30cdc916ca0

root@iZ232ngsvp8Z:~#docker run -it --link some-postgres:postgres --rm postgres sh -c 'exec psql -h"$POSTGRES_PORT_5432_TCP_ADDR" -p"$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

Password for userpostgres:

psql (9.4.4)

Type"help" for help.

 

postgres=# \q

root@iZ232ngsvp8Z:~#docker start 80c759a286cb

80c759a286cb

root@iZ232ngsvp8Z:~#docker run -it --link some-app:postgres --rm postgres sh -c 'exec psql -h"$POSTGRES_PORT_5432_TCP_ADDR" -p"$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

psql (9.4.4)

Type"help" for help.

 

postgres=# select1+1;

 ?column?

----------

        2

(1 row)

 

postgres=# \q

root@iZ232ngsvp8Z:~#docker run --name postgres1 -e POSTGRES_PASSWORD=mysecretpassword -d postgres

291d3506079f789efc22fd136ae8885699eb63f3793580dd4a8eb8d3a4fb6978

root@iZ232ngsvp8Z:~#docker start 80c759a286cb^C

root@iZ232ngsvp8Z:~#docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES

291d3506079f        postgres           "/docker-entrypoint.s"  23 seconds ago      Up 22 seconds                 5432/tcp            postgres1

80c759a286cb        postgres           "/docker-entrypoint.s"  7 minutes ago       Up About aminute             5432/tcp            some-app

c30cdc916ca0        postgres            "/docker-entrypoint.s"   8 minutes ago       Up 2 minutes                  5432/tcp            some-postgres

c52cf047e34b        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            sick_tesla

b85e40d1dbfa        ubuntu              "/bin/bash"              7 hours ago         Exited (137) 23 minutes ago                       trusting_poitras

0f699f850631        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            evil_bohr

b65260158cda        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            goofy_heisenberg

f9edf202c967        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            furious_bhabha

218cae3a7c80        ubuntu              "/bin/bash"              7 hours ago         Exited (0) 7 hours ago                            stoic_mestorf

fda911eaffbd        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            compassionate_noyce

85e83c099417        hello-world         "/hello"                 7 hours ago         Exited (0) 7 hours ago                            mad_panini

68e9124ed0b9        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           clever_lalande

b6de6337737c        hello-world         "/hello"                 23 hours ago        Exited (0) 23 hours ago                           sleepy_engelbart

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker run -it --link some-app^Costgres --rm postgres sh -c 'exec psql -h"$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT"-U postgres'

root@iZ232ngsvp8Z:~#

root@iZ232ngsvp8Z:~#docker run -it --link postgres1:postgres --rm postgres sh -c 'exec psql -h"$POSTGRES_PORT_5432_TCP_ADDR" -p"$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

Password for userpostgres:

psql (9.4.4)

Type"help" for help.

 

postgres=# \d

No relations found.

postgres=# createtable t1(id int);

CREATE TABLE

postgres=# insertinto t1 select generate_series(1,100);

INSERT 0 100

postgres=# \q

root@iZ232ngsvp8Z:~#docker run --name postgres1 -e POSTGRES_PASSWORD=mysecretpassword -d postgres

Error response fromdaemon: Conflict. The name "postgres1" is already in use by container291d3506079f. You have to delete (or rename) that container to be able to reusethat name.

root@iZ232ngsvp8Z:~#docker run -it --link some-app:postgres --rm postgres sh -c 'exec psql -h"$POSTGRES_PORT_5432_TCP_ADDR" -p"$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

psql (9.4.4)

Type"help" for help.

 

postgres=# \d

No relations found.

postgres=# \q

root@iZ232ngsvp8Z:~#docker run -it --link postgres1:postgres --rm postgres sh -c 'exec psql -h"$POSTGRES_PORT_5432_TCP_ADDR" -p"$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

Password for userpostgres:

psql (9.4.4)

Type"help" for help.

 

postgres=# \d

        List of relations

 Schema | Name | Type  | Owner  

--------+------+-------+----------

 public | t1  | table | postgres

(1 row)

 

postgres=# select *from t1;

 id 

-----

   1

   2

   3

   4

   5

 

 

 

 

 

 

 

 

 

 

 

 

 

参考:

http://dockerpool.com/static/books/docker_practice/repository/README.html

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐