docker

简介:

Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的、可移植的、自给自足的容器。开发者在笔记本上编译测试通过的容器可以批量地在生产环境中部署,包括VMs(虚拟机)、bare metal、OpenStack 集群和其他的基础应用平台。


Docker通常用于如下场景:

  • web应用的自动化打包和发布;
  • 自动化测试和持续集成、发布;
  • 在服务型环境中部署和调整数据库或其他的后台应用;
  • 从头编译或者扩展现有的OpenShift或Cloud Foundry平台来搭建自己的PaaS环境。

Docker系统有两个程序:docker服务端和docker客户端。

  • docker服务端是一个服务进程,管理着所有的容器。
  • docker客户端则扮演着docker服务端的远程控制器,可以用来控制docker的服务端进程。
  • 大部分情况下,docker服务端和客户端运行在一台机器上。

一、docker安装

1、系统版本检查:

Docker需要一个64位系统的红帽系统,内核的版本必须大于3.10

1.[root@localhost lcr]# uname -r
2.3.10.0-514.26.2.el7.x86_64

2、安装

1、脚本安装

1.yum install -y docker
1.[root@localhost lcr]# docker version
2.Client:
3. Version: 17.07.0-ce
4. API version: 1.31
5. Go version: go1.8.3
6. Git commit: 8784753
7. Built: Tue Aug 29 17:42:01 2017
8. OS/Arch: linux/amd64
9.Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

2、库安装

1.yum install -y docker

3、启动docker

1.service docker start

4、设置开机启动

1.chkconfig docker on

5、尝试运行

1.[root@localhost lcr]# docker run hello-world
2.Unable to find image 'hello-world:latest' locally
3.latest: Pulling from library/hello-world
4.5b0f327be733: Pull complete
5.Digest: sha256:1f19634d26995c320618d94e6f29c09c6589d5df3c063287a00e6de8458f8242
6.Status: Downloaded newer image for hello-world:latest
7.
8.Hello from Docker!
9.This message shows that your installation appears to be working correctly.
10.
11.To generate this message, Docker took the following steps:
12. 1. The Docker client contacted the Docker daemon.
13. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
14. 3. The Docker daemon created a new container from that image which runs the
15. executable that produces the output you are currently reading.
16. 4. The Docker daemon streamed that output to the Docker client, which sent it
17. to your terminal.
18.
19.To try something more ambitious, you can run an Ubuntu container with:
20. $ docker run -it ubuntu bash
21.
22.Share images, automate workflows, and more with a free Docker ID:
23. https://cloud.docker.com/
24.
25.For more examples and ideas, visit:
26. https://docs.docker.com/engine/userguide/

二、创建docker用户组

usermod指令


语法

usermod(选项)(参数)


选项

选项名 说明
-c<备注> 修改用户帐号的备注文字;
-d<登入目录> 修改用户登入时的目录;
-e<有效期限> 修改帐号的有效期限;
-f<缓冲天数> 修改在密码过期后多少天即关闭该帐号;
-g<群组> 修改用户所属的群组;
-G<群组> 修改用户所属的附加群组;
-l<帐号名称> 修改用户帐号名称;
-L 锁定用户密码,使密码无效;
-s 修改用户登入后所使用的shell;
-u 修改用户ID;
-U 解除密码锁定。

参数

登录名:指定要修改信息的用户登录名。


实例

1.usermod -G staff newuser2
1.usermod -l newuser1 newuser
1.usermod -L newuser1
1.usermod -U newuser1

创建docker用户组

创建用户组

1.groupadd -g 122 docker

关于groupadd指令

选项 说明
-g 指定新建工作组的id
-r 创建系统工作组,系统工作组的组ID小于500
-K 覆盖配置文件“/ect/login.defs”
-o 允许添加组ID号不唯一的工作组

1.groupadd -g 344 linuxde

此时在/etc/passwd文件中产生一个组ID(GID)是344的项目

添加用户

使用root权限将用户添加到用户组

1.usermod -aG docker your_username

实践

1.[root@centos-1 lcr]# usermod -aG docker lcr

重新登录系统,让权限生效
普通用户运行docker

1.[lcr@centos-1 ~]$ docker run hello-world
2.Unable to find image 'hello-world:latest' locally
3.Trying to pull repository docker.io/library/hello-world ...
4.latest: Pulling from docker.io/library/hello-world
5.
6.5b0f327be733: Pull complete
7.Digest: sha256:1f19634d26995c320618d94e6f29c09c6589d5df3c063287a00e6de8458f8242
8.
9.Hello from Docker!
10.This message shows that your installation appears to be working correctly.
11.
12.To generate this message, Docker took the following steps:
13. 1. The Docker client contacted the Docker daemon.
14. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
15. 3. The Docker daemon created a new container from that image which runs the
16. executable that produces the output you are currently reading.
17. 4. The Docker daemon streamed that output to the Docker client, which sent it
18. to your terminal.
19.
20.To try something more ambitious, you can run an Ubuntu container with:
21. $ docker run -it ubuntu bash
22.
23.Share images, automate workflows, and more with a free Docker ID:
24. https://cloud.docker.com/
25.
26.For more examples and ideas, visit:
27. https://docs.docker.com/engine/userguide/

对比未添加用户组的

1.[root@localhost lcr]# exit
2.exit
3.[lcr@localhost ~]$ docker run hello-world
4.docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.31/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
5.See 'docker run --help'.

三、删除docker

1、查找docker安装包

1.yum list installed | grep docker
1.[lcr@localhost ~]$ yum list installed | grep docker
2.docker-ce.x86_64 17.07.0.ce-1.el7.centos @docker-ce-edge

2、删除docker

1.yum -y remove docker-engine.x86_64
2.````
3.
4.
5.>###3、清除镜像和容器文件
6.前两步操作不会删除镜像和容器文件
7.
8.
9.
10.
11.<div class="se-preview-section-delimiter"></div>
12.

rm -rf /var/lib/docker

1.
2.>实践操作
3.
4.
5.
6.
7.<div class="se-preview-section-delimiter"></div>
8.

[root@localhost lcr]# yum list installed |grep docker
docker-ce.x86_64 17.07.0.ce-1.el7.centos @docker-ce-edge
[root@localhost lcr]# yum -y remove docker-ce.x86_64
已加载插件:fastestmirror, langpacks
正在解决依赖关系
–> 正在检查事务
—> 软件包 docker-ce.x86_64.0.17.07.0.ce-1.el7.centos 将被 删除
–> 解决依赖关系完成

依赖关系解决

====================================

Package 架构 版本 源 大小

正在删除:
docker-ce x86_64 17.07.0.ce-1.el7.centos @docker-ce-edge 75 M

事务概要

移除 1 软件包

安装大小:75 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在删除 : docker-ce-17.07.0.ce-1.el7.centos.x86_64 1/1
验证中 : docker-ce-17.07.0.ce-1.el7.centos.x86_64 1/1

删除:
docker-ce.x86_64 0:17.07.0.ce-1.el7.centos

完毕!

1.
2.
3.
4.
5.
6.
7.<div class="se-preview-section-delimiter"></div>
8.
9.#四、搜索镜像
10.
11.
12.
13.
14.<div class="se-preview-section-delimiter"></div>
15.

[lcr@centos-1 ~]$ docker search tutorial
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/learn/tutorial 29
docker.io docker.io/georgeyord/reactjs-tutorial This is the backend of the React comment b… 4 [OK]
docker.io docker.io/chris24walsh/flask-aws-tutorial Runs a simple flask webapp demo, with the … 1 [OK]
docker.io docker.io/mhausenblas/kairosdb-tutorial GitHub fetcher for KairosDB tutorial 1 [OK]
docker.io docker.io/abarkai/aws-lambda-ecs-tutorial 0
docker.io docker.io/activeeon/par-connector-tutorial Do the par-connector tutorial with R. The … 0 [OK]
docker.io docker.io/camphor/python-tutorial camphor-/python-tutorial 0 [OK]
docker.io docker.io/cloudboost/tutorial 0
docker.io docker.io/emooti/tutorial2build Tutorial2 Build 0
docker.io docker.io/fiware/tutorials.tourguide-app FIWARE Tour Guide App sample application 0 [OK]
docker.io docker.io/imiell/git-101-tutorial 0
docker.io docker.io/imiell/git-rebase-tutorial 0
docker.io docker.io/jbalexandre/docker-tutorial 0
docker.io docker.io/kidikarus/concourse-tutorial-47-tasks 0
docker.io docker.io/kobe25/docker-tutorial Docker Tutorial 0 [OK]
docker.io docker.io/krishnatest/docker-nodejs-tutorialkk docker-nodejs-tutorialkk 0
docker.io docker.io/lukasheinrich/quickana-tutorial Image for the analysis code built from htt… 0
docker.io docker.io/microsoft/aci-tutorial-sidecar 0
docker.io docker.io/muli/gluon-tutorials-zh https://github.com/mli/gluon-tutorials-zh 0 [OK]
docker.io docker.io/onekit/rest-tutorial REST API server-side tutorial. How to do i… 0 [OK]
docker.io docker.io/paddledev/paddle-tutorial images that paddle tutorials use. 0
docker.io docker.io/paulcos11/docker-tutorial docker tutorial 0 [OK]
docker.io docker.io/schwamster/docker-tutorial 0
docker.io docker.io/starkandwayne/concourse-tutorial 0
docker.io docker.io/starkandwayne/concourse-tutorial-ci 0

1.
2.
3.
4.
5.<div class="se-preview-section-delimiter"></div>
6.
7.![Alt text](./1506154324133.png)
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.<div class="se-preview-section-delimiter"></div>
18.
19.#五、下载镜像
20.
21.
22.
23.
24.<div class="se-preview-section-delimiter"></div>
25.

[lcr@centos-1 ~]$ docker pull learn/tutorial
Using default tag: latest
Trying to pull repository docker.io/learn/tutorial …
latest: Pulling from docker.io/learn/tutorial
271134aeb542: Pull complete
Digest: sha256:2933b82e7c2a72ad8ea89d58af5d1472e35dacd5b7233577483f58ff8f9338bd

1.
2.
3.
4.
5.
6.
7.<div class="se-preview-section-delimiter"></div>
8.
9.#六、运行容器
10.>docker容器可以理解为在沙盒中运行的进程。
11.这个沙盒包含了该进程运行所必须的资源,包括文件系统、系统类库、shell 环境等等。
12.但这个沙盒默认是不会运行任何程序的。
13.你需要在沙盒中运行一个进程来启动某一个容器。
14.这个进程是该容器的唯一进程,所以当该进程结束的时候,容器也会完全的停止。
15.
16.
17.
18.**`docker run`命令有两个参数:**
19.- 一个是镜像名,
20.- 一个是要在镜像中运行的命令。
21.
22.
23.
24.
25.
26.<div class="se-preview-section-delimiter"></div>
27.

[lcr@centos-1 ~]

1.
2.
3.
4.
5.
6.<div class="se-preview-section-delimiter"></div>
7.
8.#七、容器中安装新的程序
9.tutorial镜像是基于ubuntu
10.
11.在执行apt-get 命令的时候,要带上-y参数。如果不指定-y参数的话,apt-get命令会进入交互模式,需要用户输入命令来进行确认,但在docker环境中是无法响应这种交互的。
12.
13.>**实践**
14.
15.- 安装apache
16.
17.
18.
19.
20.<div class="se-preview-section-delimiter"></div>
21.

[lcr@centos-1 ~]$ docker run learn/tutorial apt-get -y install apache2
Reading package lists…
Building dependency tree…
The following extra packages will be installed:
apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common file libapr1
libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libasn1-8-heimdal
libcap2 libclass-isa-perl libexpat1 libgcrypt11 libgdbm3 libgnutls26
libgpg-error0 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal
libheimntlm0-heimdal libhx509-5-heimdal libkrb5-26-heimdal libldap-2.4-2
libmagic1 libp11-kit0 libroken18-heimdal libsasl2-2 libsasl2-modules
libsqlite3-0 libswitch-perl libtasn1-3 libwind0-heimdal mime-support netbase
openssl perl perl-modules ssl-cert
Suggested packages:
www-browser apache2-doc apache2-suexec apache2-suexec-custom ufw rng-tools
gnutls-bin libsasl2-modules-otp libsasl2-modules-ldap libsasl2-modules-sql
libsasl2-modules-gssapi-mit libsasl2-modules-gssapi-heimdal ca-certificates
perl-doc libterm-readline-gnu-perl libterm-readline-perl-perl make
libpod-plainer-perl openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common file
libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
libasn1-8-heimdal libcap2 libclass-isa-perl libexpat1 libgcrypt11 libgdbm3
libgnutls26 libgpg-error0 libgssapi3-heimdal libhcrypto4-heimdal
libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal
libkrb5-26-heimdal libldap-2.4-2 libmagic1 libp11-kit0 libroken18-heimdal
libsasl2-2 libsasl2-modules libsqlite3-0 libswitch-perl libtasn1-3
libwind0-heimdal mime-support netbase openssl perl perl-modules ssl-cert
0 upgraded, 40 newly installed, 0 to remove and 0 not upgraded.
Need to get 13.1 MB of archives.
After this operation, 49.0 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ precise/main libexpat1 amd64 2.0.1-7.2ubuntu1 [131 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ precise/main libsqlite3-0 amd64 3.7.9-2ubuntu1 [348 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ precise/main libroken18-heimdal amd64 1.6~git20120311.dfsg.1-2 [46.0 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ precise/main libasn1-8-heimdal amd64 1.6~git20120311.dfsg.1-2 [220 kB]
Get:5 http://archive.ubuntu.com/ubuntu/ precise/main libgpg-error0 amd64 1.10-2ubuntu1 [14.5 kB]
Get:6 http://archive.ubuntu.com/ubuntu/ precise/main libgcrypt11 amd64 1.5.0-3 [280 kB]
Get:7 http://archive.ubuntu.com/ubuntu/ precise/main libgdbm3 amd64 1.8.3-10 [35.3 kB]
Get:8 http://archive.ubuntu.com/ubuntu/ precise/main libp11-kit0 amd64 0.12-2ubuntu1 [34.3 kB]
Get:9 http://archive.ubuntu.com/ubuntu/ precise/main libtasn1-3 amd64 2.10-1ubuntu1 [43.1 kB]
Get:10 http://archive.ubuntu.com/ubuntu/ precise/main libgnutls26 amd64 2.12.14-5ubuntu3 [459 kB]
Get:11 http://archive.ubuntu.com/ubuntu/ precise/main libhcrypto4-heimdal amd64 1.6~git20120311.dfsg.1-2 [103 kB]
Get:12 http://archive.ubuntu.com/ubuntu/ precise/main libheimbase1-heimdal amd64 1.6~git20120311.dfsg.1-2 [33.0 kB]
Get:13 http://archive.ubuntu.com/ubuntu/ precise/main libwind0-heimdal amd64 1.6~git20120311.dfsg.1-2 [77.8 kB]
Get:14 http://archive.ubuntu.com/ubuntu/ precise/main libhx509-5-heimdal amd64 1.6~git20120311.dfsg.1-2 [125 kB]
Get:15 http://archive.ubuntu.com/ubuntu/ precise/main libkrb5-26-heimdal amd64 1.6~git20120311.dfsg.1-2 [234 kB]
Get:16 http://archive.ubuntu.com/ubuntu/ precise/main libheimntlm0-heimdal amd64 1.6~git20120311.dfsg.1-2 [16.0 kB]
Get:17 http://archive.ubuntu.com/ubuntu/ precise/main libgssapi3-heimdal amd64 1.6~git20120311.dfsg.1-2 [108 kB]
Get:18 http://archive.ubuntu.com/ubuntu/ precise/main libsasl2-2 amd64 2.1.25.dfsg1-3 [69.8 kB]
Get:19 http://archive.ubuntu.com/ubuntu/ precise/main libldap-2.4-2 amd64 2.4.28-1.1ubuntu4 [186 kB]
Get:20 http://archive.ubuntu.com/ubuntu/ precise/main libcap2 amd64 1:2.22-1ubuntu3 [12.0 kB]
Get:21 http://archive.ubuntu.com/ubuntu/ precise/main libmagic1 amd64 5.09-2 [217 kB]
Get:22 http://archive.ubuntu.com/ubuntu/ precise/main file amd64 5.09-2 [19.7 kB]
Get:23 http://archive.ubuntu.com/ubuntu/ precise/main mime-support all 3.51-1ubuntu1 [30.7 kB]
Get:24 http://archive.ubuntu.com/ubuntu/ precise/main netbase all 4.47ubuntu1 [15.0 kB]
Get:25 http://archive.ubuntu.com/ubuntu/ precise/main libsasl2-modules amd64 2.1.25.dfsg1-3 [63.4 kB]
Get:26 http://archive.ubuntu.com/ubuntu/ precise/main openssl amd64 1.0.1-4ubuntu3 [523 kB]
Get:27 http://archive.ubuntu.com/ubuntu/ precise/main libapr1 amd64 1.4.6-1 [89.6 kB]
Get:28 http://archive.ubuntu.com/ubuntu/ precise/main libaprutil1 amd64 1.3.12+dfsg-3 [74.6 kB]
Get:29 http://archive.ubuntu.com/ubuntu/ precise/main libaprutil1-dbd-sqlite3 amd64 1.3.12+dfsg-3 [10.4 kB]
Get:30 http://archive.ubuntu.com/ubuntu/ precise/main libaprutil1-ldap amd64 1.3.12+dfsg-3 [8044 B]
Get:31 http://archive.ubuntu.com/ubuntu/ precise/main apache2.2-bin amd64 2.2.22-1ubuntu1 [1337 kB]

Message from syslogd@centos-1 at Sep 23 16:32:39 …
kernel:unregister_netdevice: waiting for lo to become free. Usage count = 0
Get:32 http://archive.ubuntu.com/ubuntu/ precise/main apache2-utils amd64 2.2.22-1ubuntu1 [91.0 kB]
Get:33 http://archive.ubuntu.com/ubuntu/ precise/main libswitch-perl all 2.16-2 [19.2 kB]
Get:34 http://archive.ubuntu.com/ubuntu/ precise/main libclass-isa-perl all 0.36-3 [11.9 kB]
Get:35 http://archive.ubuntu.com/ubuntu/ precise/main perl-modules all 5.14.2-6ubuntu2 [3369 kB]
Get:36 http://archive.ubuntu.com/ubuntu/ precise/main perl amd64 5.14.2-6ubuntu2 [4417 kB]
Get:37 http://archive.ubuntu.com/ubuntu/ precise/main apache2.2-common amd64 2.2.22-1ubuntu1 [228 kB]
Get:38 http://archive.ubuntu.com/ubuntu/ precise/main apache2-mpm-worker amd64 2.2.22-1ubuntu1 [2294 B]
Get:39 http://archive.ubuntu.com/ubuntu/ precise/main apache2 amd64 2.2.22-1ubuntu1 [1484 B]
Get:40 http://archive.ubuntu.com/ubuntu/ precise/main ssl-cert all 1.0.28 [12.2 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 13.1 MB in 1min 25s (153 kB/s)
Selecting previously unselected package libexpat1.
(Reading database … 7545 files and directories currently installed.)
Unpacking libexpat1 (from …/libexpat1_2.0.1-7.2ubuntu1_amd64.deb) …
Selecting previously unselected package libsqlite3-0.
Unpacking libsqlite3-0 (from …/libsqlite3-0_3.7.9-2ubuntu1_amd64.deb) …
Selecting previously unselected package libroken18-heimdal.
Unpacking libroken18-heimdal (from …/libroken18-heimdal_1.6~git20120311.dfsg.1-2_amd64.deb) …
Selecting previously unselected package libasn1-8-heimdal.
Unpacking libasn1-8-heimdal (from …/libasn1-8-heimdal_1.6~git20120311.dfsg.1-2_amd64.deb) …
Selecting previously unselected package libgpg-error0.
Unpacking libgpg-error0 (from …/libgpg-error0_1.10-2ubuntu1_amd64.deb) …
Selecting previously unselected package libgcrypt11.
Unpacking libgcrypt11 (from …/libgcrypt11_1.5.0-3_amd64.deb) …
Selecting previously unselected package libgdbm3.
Unpacking libgdbm3 (from …/libgdbm3_1.8.3-10_amd64.deb) …
Selecting previously unselected package libp11-kit0.
Unpacking libp11-kit0 (from …/libp11-kit0_0.12-2ubuntu1_amd64.deb) …
Selecting previously unselected package libtasn1-3.
Unpacking libtasn1-3 (from …/libtasn1-3_2.10-1ubuntu1_amd64.deb) …
Selecting previously unselected package libgnutls26.
Unpacking libgnutls26 (from …/libgnutls26_2.12.14-5ubuntu3_amd64.deb) …
Selecting previously unselected package libhcrypto4-heimdal.
Unpacking libhcrypto4-heimdal (from …/libhcrypto4-heimdal_1.6~git20120311.dfsg.1-2_amd64.deb) …
Selecting previously unselected package libheimbase1-heimdal.
Unpacking libheimbase1-heimdal (from …/libheimbase1-heimdal_1.6~git20120311.dfsg.1-2_amd64.deb) …
Selecting previously unselected package libwind0-heimdal.
Unpacking libwind0-heimdal (from …/libwind0-heimdal_1.6~git20120311.dfsg.1-2_amd64.deb) …
Selecting previously unselected package libhx509-5-heimdal.
Unpacking libhx509-5-heimdal (from …/libhx509-5-heimdal_1.6~git20120311.dfsg.1-2_amd64.deb) …
Selecting previously unselected package libkrb5-26-heimdal.
Unpacking libkrb5-26-heimdal (from …/libkrb5-26-heimdal_1.6~git20120311.dfsg.1-2_amd64.deb) …
Selecting previously unselected package libheimntlm0-heimdal.
Unpacking libheimntlm0-heimdal (from …/libheimntlm0-heimdal_1.6~git20120311.dfsg.1-2_amd64.deb) …
Selecting previously unselected package libgssapi3-heimdal.
Unpacking libgssapi3-heimdal (from …/libgssapi3-heimdal_1.6~git20120311.dfsg.1-2_amd64.deb) …
Selecting previously unselected package libsasl2-2.
Unpacking libsasl2-2 (from …/libsasl2-2_2.1.25.dfsg1-3_amd64.deb) …
Selecting previously unselected package libldap-2.4-2.
Unpacking libldap-2.4-2 (from …/libldap-2.4-2_2.4.28-1.1ubuntu4_amd64.deb) …
Selecting previously unselected package libcap2.
Unpacking libcap2 (from …/libcap2_1%3a2.22-1ubuntu3_amd64.deb) …
Selecting previously unselected package libmagic1.
Unpacking libmagic1 (from …/libmagic1_5.09-2_amd64.deb) …
Selecting previously unselected package file.
Unpacking file (from …/archives/file_5.09-2_amd64.deb) …
Selecting previously unselected package mime-support.
Unpacking mime-support (from …/mime-support_3.51-1ubuntu1_all.deb) …
Selecting previously unselected package netbase.
Unpacking netbase (from …/netbase_4.47ubuntu1_all.deb) …
Selecting previously unselected package libsasl2-modules.
Unpacking libsasl2-modules (from …/libsasl2-modules_2.1.25.dfsg1-3_amd64.deb) …
Selecting previously unselected package openssl.
Unpacking openssl (from …/openssl_1.0.1-4ubuntu3_amd64.deb) …
Selecting previously unselected package libapr1.
Unpacking libapr1 (from …/libapr1_1.4.6-1_amd64.deb) …
Selecting previously unselected package libaprutil1.
Unpacking libaprutil1 (from …/libaprutil1_1.3.12+dfsg-3_amd64.deb) …
Selecting previously unselected package libaprutil1-dbd-sqlite3.
Unpacking libaprutil1-dbd-sqlite3 (from …/libaprutil1-dbd-sqlite3_1.3.12+dfsg-3_amd64.deb) …
Selecting previously unselected package libaprutil1-ldap.
Unpacking libaprutil1-ldap (from …/libaprutil1-ldap_1.3.12+dfsg-3_amd64.deb) …
Selecting previously unselected package apache2.2-bin.
Unpacking apache2.2-bin (from …/apache2.2-bin_2.2.22-1ubuntu1_amd64.deb) …
Selecting previously unselected package apache2-utils.
Unpacking apache2-utils (from …/apache2-utils_2.2.22-1ubuntu1_amd64.deb) …
Selecting previously unselected package libswitch-perl.
Unpacking libswitch-perl (from …/libswitch-perl_2.16-2_all.deb) …
Selecting previously unselected package libclass-isa-perl.
Unpacking libclass-isa-perl (from …/libclass-isa-perl_0.36-3_all.deb) …
Selecting previously unselected package perl-modules.
Unpacking perl-modules (from …/perl-modules_5.14.2-6ubuntu2_all.deb) …
Selecting previously unselected package perl.
Unpacking perl (from …/perl_5.14.2-6ubuntu2_amd64.deb) …
Selecting previously unselected package apache2.2-common.
Unpacking apache2.2-common (from …/apache2.2-common_2.2.22-1ubuntu1_amd64.deb) …
Selecting previously unselected package apache2-mpm-worker.
Unpacking apache2-mpm-worker (from …/apache2-mpm-worker_2.2.22-1ubuntu1_amd64.deb) …
Selecting previously unselected package apache2.
Unpacking apache2 (from …/apache2_2.2.22-1ubuntu1_amd64.deb) …
Selecting previously unselected package ssl-cert.
Unpacking ssl-cert (from …/ssl-cert_1.0.28_all.deb) …
Setting up libexpat1 (2.0.1-7.2ubuntu1) …
Setting up libsqlite3-0 (3.7.9-2ubuntu1) …
Setting up libroken18-heimdal (1.6~git20120311.dfsg.1-2) …
Setting up libasn1-8-heimdal (1.6~git20120311.dfsg.1-2) …
Setting up libgpg-error0 (1.10-2ubuntu1) …
Setting up libgcrypt11 (1.5.0-3) …
Setting up libgdbm3 (1.8.3-10) …
Setting up libp11-kit0 (0.12-2ubuntu1) …
Setting up libtasn1-3 (2.10-1ubuntu1) …
Setting up libgnutls26 (2.12.14-5ubuntu3) …
Setting up libhcrypto4-heimdal (1.6~git20120311.dfsg.1-2) …
Setting up libheimbase1-heimdal (1.6~git20120311.dfsg.1-2) …
Setting up libwind0-heimdal (1.6~git20120311.dfsg.1-2) …
Setting up libhx509-5-heimdal (1.6~git20120311.dfsg.1-2) …
Setting up libkrb5-26-heimdal (1.6~git20120311.dfsg.1-2) …
Setting up libheimntlm0-heimdal (1.6~git20120311.dfsg.1-2) …
Setting up libgssapi3-heimdal (1.6~git20120311.dfsg.1-2) …
Setting up libsasl2-2 (2.1.25.dfsg1-3) …
Setting up libldap-2.4-2 (2.4.28-1.1ubuntu4) …
Setting up libcap2 (1:2.22-1ubuntu3) …
Setting up libmagic1 (5.09-2) …
Setting up file (5.09-2) …
Setting up mime-support (3.51-1ubuntu1) …
update-alternatives: using /usr/bin/see to provide /usr/bin/view (view) in auto mode.
Setting up netbase (4.47ubuntu1) …
Setting up libsasl2-modules (2.1.25.dfsg1-3) …
Setting up openssl (1.0.1-4ubuntu3) …
Setting up libapr1 (1.4.6-1) …
Setting up libaprutil1 (1.3.12+dfsg-3) …
Setting up libaprutil1-dbd-sqlite3 (1.3.12+dfsg-3) …
Setting up libaprutil1-ldap (1.3.12+dfsg-3) …
Setting up apache2.2-bin (2.2.22-1ubuntu1) …
Setting up apache2-utils (2.2.22-1ubuntu1) …
Setting up libclass-isa-perl (0.36-3) …
Setting up ssl-cert (1.0.28) …
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
Setting up libswitch-perl (2.16-2) …
Setting up perl-modules (5.14.2-6ubuntu2) …
Setting up perl (5.14.2-6ubuntu2) …
update-alternatives: using /usr/bin/prename to provide /usr/bin/rename (rename) in auto mode.
Setting up apache2.2-common (2.2.22-1ubuntu1) …
Enabling site default.
Enabling module alias.
Enabling module autoindex.
Enabling module dir.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module status.
Enabling module auth_basic.
Enabling module deflate.
Enabling module authz_default.
Enabling module authz_user.
Enabling module authz_groupfile.
Enabling module authn_file.
Enabling module authz_host.
Enabling module reqtimeout.
Setting up apache2-mpm-worker (2.2.22-1ubuntu1) …

1.
2.
3.
4.
5.
6.<div class="se-preview-section-delimiter"></div>
7.
8.#八、保存对容器的修改
9.当你对某一个容器做了修改之后(通过在容器中运行某一个命令),可以把对容器的修改保存下来,这样下次可以从保存后的最新状态运行该容器。
10.docker中保存状态的过程称之为committing,它保存的新旧状态之间的区别,从而产生一个新的版本。
11.
12.
13.
14.
15.
16.
17.<div class="se-preview-section-delimiter"></div>
18.

[lcr@centos-1 ~]$ docker commit
“docker commit” requires at least 1 and at most 2 argument(s).
See ‘docker commit –help’.

Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Create a new image from a container’s changes
[lcr@centos-1 ~]$ docker commit –help

Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Create a new image from a container’s changes

Options:
-a, –author string Author (e.g., “John Hannibal Smith hannibal@a-team.com”)
-c, –change value Apply Dockerfile instruction to the created image (default [])
–help Print usage
-m, –message string Commit message
-p, –pause Pause container during commit (default true)

1.
2.>使用``docker ps -l``获取当前容器的id
3.
4.
5.
6.
7.<div class="se-preview-section-delimiter"></div>
8.

[lcr@centos-1 ~]$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d98186ab3b4b learn/tutorial “ls” 3 minutes ago Exited (0) 3 minutes ago pensive_darwin

1.
2.
3.
4.
5.<div class="se-preview-section-delimiter"></div>
6.
7.![Alt text](./1506156345602.png)
8.
9.
10.>**使用commit保存版本**
11.>- 需要指定要提交保存容器的ID。(通过docker ps -l 命令获得)
12.- 无需拷贝完整的id,通常来讲最开始的三至四个字母即可区分
13.
14.
15.
16.
17.<div class="se-preview-section-delimiter"></div>
18.

docker commit id name

1.
2.
3.
4.
5.<div class="se-preview-section-delimiter"></div>
6.

[lcr@centos-1 ~]$ docker commit d9818 learn/apache
sha256:6609e42ac8818a6b32e88b6ab6f76d3ef28d6d50bf97ab5b628ea1391c711169

1.下次运行可以使用`learn/apache`的镜像名运行
2.
3.
4.
5.
6.
7.<div class="se-preview-section-delimiter"></div>
8.

[lcr@centos-1 ~]$ docker run learn/ping ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38: icmp_req=1 ttl=53 time=4.52 ms
64 bytes from 14.215.177.38: icmp_req=2 ttl=53 time=167 ms
64 bytes from 14.215.177.38: icmp_req=3 ttl=53 time=5.08 ms
64 bytes from 14.215.177.38: icmp_req=4 ttl=53 time=88.8 ms
64 bytes from 14.215.177.38: icmp_req=5 ttl=53 time=267 ms
64 bytes from 14.215.177.38: icmp_req=6 ttl=53 time=340 ms
64 bytes from 14.215.177.38: icmp_req=7 ttl=53 time=5.15 ms
64 bytes from 14.215.177.38: icmp_req=8 ttl=53 time=4.78 ms
64 bytes from 14.215.177.38: icmp_req=9 ttl=53 time=4.76 ms
64 bytes from 14.215.177.38: icmp_req=10 ttl=53 time=95.7 ms
64 bytes from 14.215.177.38: icmp_req=11 ttl=53 time=167 ms
64 bytes from 14.215.177.38: icmp_req=12 ttl=53 time=78.2 ms
64 bytes from 14.215.177.38: icmp_req=13 ttl=53 time=103 ms
64 bytes from 14.215.177.38: icmp_req=14 ttl=53 time=79.2 ms
64 bytes from 14.215.177.38: icmp_req=15 ttl=53 time=5.15 ms
64 bytes from 14.215.177.38: icmp_req=16 ttl=53 time=5.72 ms
^C
— www.a.shifen.com ping statistics —
16 packets transmitted, 16 received, 0% packet loss, time 15019ms
rtt min/avg/max/mdev = 4.523/88.953/340.158/99.041 ms

1.
2.
3.
4.
5.
6.<div class="se-preview-section-delimiter"></div>
7.
8.#九、检查运行中的镜像
9.
10.
11.
12.
13.<div class="se-preview-section-delimiter"></div>
14.

docker inspect ID

1.
2.
3.
4.
5.
6.<div class="se-preview-section-delimiter"></div>
7.

[root@centos-1 image]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
642ce9a6d782 learn/ping “ping www.baidu.com” 10 seconds ago Up 9 seconds silly_snyder

1.
2.
3.
4.
5.<div class="se-preview-section-delimiter"></div>
6.
7.![Alt text](./1506157339151.png)
8.
9.
10.
11.
12.
13.<div class="se-preview-section-delimiter"></div>
14.

[root@centos-1 image]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
642ce9a6d782 learn/ping “ping www.baidu.com” 2 minutes ago Up 2 minutes silly_snyder
[root@centos-1 image]# docker inspect 642ce
[
{
“Id”: “642ce9a6d7820c50af87e82a59d37d63195a36e9f1df13527f3773cc81e34c5f”,
“Created”: “2017-09-23T09:01:52.682497441Z”,
“Path”: “ping”,
“Args”: [
“www.baidu.com”
],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 9750,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2017-09-23T09:01:53.106452825Z”,
“FinishedAt”: “0001-01-01T00:00:00Z”
},
“Image”: “sha256:7356f5f12f390c4d076e455a52e971f591c8fba20c87f0670f505252d13aff9f”,
“ResolvConfPath”: “/var/lib/docker/containers/642ce9a6d7820c50af87e82a59d37d63195a36e9f1df13527f3773cc81e34c5f/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/642ce9a6d7820c50af87e82a59d37d63195a36e9f1df13527f3773cc81e34c5f/hostname”,
“HostsPath”: “/var/lib/docker/containers/642ce9a6d7820c50af87e82a59d37d63195a36e9f1df13527f3773cc81e34c5f/hosts”,
“LogPath”: “”,
“Name”: “/silly_snyder”,
“RestartCount”: 0,
“Driver”: “devicemapper”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: null,
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “journald”,
“Config”: {}
},
“NetworkMode”: “default”,
“PortBindings”: {},
“RestartPolicy”: {
“Name”: “no”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: null,
“CapAdd”: null,
“CapDrop”: null,
“Dns”: [],
“DnsOptions”: [],
“DnsSearch”: [],
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “docker-runc”,
“ConsoleSize”: [
0,
0
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: null,
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: [],
“DiskQuota”: 0,
“KernelMemory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: -1,
“OomKillDisable”: false,
“PidsLimit”: 0,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0
},
“GraphDriver”: {
“Name”: “devicemapper”,
“Data”: {
“DeviceId”: “31”,
“DeviceName”: “docker-253:0-67572828-dcd6157869fc6caf1c636ad741fa0b2a1c6f99b59c69c007a4a45309cd370616”,
“DeviceSize”: “10737418240”
}
},
“Mounts”: [],
“Config”: {
“Hostname”: “642ce9a6d782”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: true,
“AttachStderr”: true,
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [],
“Cmd”: [
“ping”,
“www.baidu.com”
],
“Image”: “learn/ping”,
“Volumes”: {},
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {}
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “a0d1b0c579eba53edf5c65af332d36df2580f54d5ec38ba88c2ce5a56f7d392d”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {},
“SandboxKey”: “/var/run/docker/netns/a0d1b0c579eb”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “2ac1139a6fb90a5c4ba98918ca32f6b9b81b6744c6be088dfe5d787b715b6322”,
“Gateway”: “172.17.0.1”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“MacAddress”: “02:42:ac:11:00:02”,
“Networks”: {
“bridge”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: null,
“NetworkID”: “a7999d70ee83b876d0a6c575f977d1cebba9aa225e5e56296a416952c381be1b”,
“EndpointID”: “2ac1139a6fb90a5c4ba98918ca32f6b9b81b6744c6be088dfe5d787b715b6322”,
“Gateway”: “172.17.0.1”,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:11:00:02”
}
}
}
}
]
[root@centos-1 image]#

1.
2.
3.
4.
5.
6.
7.<div class="se-preview-section-delimiter"></div>
8.
9.#10、使用带LAMP的镜像
10.
11.
12.
13.
14.<div class="se-preview-section-delimiter"></div>
15.

[lcr@centos-1 ~]$ docker search -s 10 lamp
Flag –stars has been deprecated, use –filter=stars=3 instead
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/linode/lamp LAMP on Ubuntu 14.04.1 LTS Container 111
docker.io docker.io/tutum/lamp Out-of-the-box LAMP image (PHP+MySQL) 64
docker.io docker.io/greyltc/lamp a super secure, up-to-date and lightweight… 58 [OK]
docker.io docker.io/reinblau/lamp [Deprecated]Dockerfile for PHP-Projects wi… 28 [OK]
docker.io docker.io/nickistre/ubuntu-lamp LAMP server on Ubuntu 20 [OK]
docker.io docker.io/janes/alpine-lamp lamp base on alpine linux 19 [OK]
docker.io docker.io/fauria/lamp Modern, developer friendly LAMP stack. Inc… 18 [OK]
docker.io docker.io/nickistre/centos-lamp LAMP on centos setup 16 [OK]

1.
2.
3.
4.
5.<div class="se-preview-section-delimiter"></div>
6.
7.![Alt text](./1506176685758.png)
8.
9.
10.
11.
12.
13.<div class="se-preview-section-delimiter"></div>
14.
15.![Alt text](./1506176734307.png)
16.
17.
18.----------------------------------------------------
19.
20.
21.
22.
23.<div class="se-preview-section-delimiter"></div>
24.
25.![Alt text](./1506176582291.png)
26.
27.
28.
29.
30.<div class="se-preview-section-delimiter"></div>
31.

[root@localhost lcr]# docker pull tutum/lamp
Using default tag: latest
Trying to pull repository docker.io/tutum/lamp …
latest: Pulling from docker.io/tutum/lamp
8387d9ff0016: Downloading 2.162 MB/65.68 MB
3b52deaaf0ed: Download complete
4bd501fad6de: Download complete
a3ed95caeb02: Download complete
790f0e8363b9: Downloading 11.86 MB/83.82 MB
11f87572ad81: Download complete
341e06373981: Download complete
709079cecfb8: Download complete
55bf9bbb788a: Download complete
b41f3cfd3d47: Download complete
70789ae370c5: Waiting
43f2fd9a6779: Waiting
6a0b3a1558bd: Waiting
934438c9af31: Waiting
1cfba20318ab: Waiting
de7f3e54c21c: Waiting
596da16c3b16: Waiting
e94007c4319f: Waiting
3c013e645156: Waiting
```