Docker 容器技术

时间:2023-03-10 02:35:50
Docker 容器技术

前言:

之前感觉Docker是一种小虚拟机,docker和KVM虚拟机之间有什么区别、联系、可以应用在什么样的生产环境?

一、Docker是什么以及和KVM的区别

1.docker概念?

Docker是基于LXC容器技术使用Go开发的开源软件,可以打包代码的运行环境+代码,并且移植性强,可以把代码的运行环境+代码打包成docker镜像,到处运行;

2.docker的设计理念

Docker的设计理念:构建(build)、运输(ship)、运行(running)

3.docker的架构

docker是C/S 架构 docker server 是服务端,我们执行的docker命令就是操作客户端;

[root@localhost zhanggen]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE -----------------------------------------------------------
[root@localhost zhanggen]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Wed -- :: CST; 6min ago
Docs: https://docs.docker.com
Main PID: (dockerd)
Memory: 75.6M
CGroup: /system.slice/docker.service
└─ /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

组成部分

Docker 容器技术

4.论docker and kvm

Docker Server 挂了所有的docker容器都会挂掉 (kvm的管理软件 和libvirtd完全隔离)

kvm是在内核级别完全虚拟化出来的虚拟机 虚拟机之间完全隔离

docker 容器是在操作系统层面进行的资源的隔离

Docker和KVM都可以进行状态的回滚

Docker 容器技术Docker 容器技术

5.docker的优势和应用场景

简化了系统配置、减少了代码和系统环境间的依赖性(运行别人的代码还要部署别人的运行环境)
代码流水线管理 代码开发---->代码测试----》代码到生产 一个docker容器搞定
减少开发部署系统环境工作,提高开发效率。
docker容器和虚拟机相比可以快速得运行起来

面向产品:把自己的系统运行环境+代码打包进docker容器,直接完产品交付;
面向开发:做为一个python开发我再也不用去装什么Python3、pip、Nginx了,我只关心我的代码怎么写?
面向测试:测试的时候不用搭建多套系统环境了
面向运行:环境一致性,系统环境可以回滚
面向架构:自动化扩容

6.docker安装、配置、操作、

Centos7 yum安装docker

{
"registry-mirrors": ["https://pee6w651.mirror.aliyuncs.com"]
}

换个阿里云的docker源 vim /etc/docker/daemon.json

查看docker日志

这个很关键,遇到报错一定不要心浮气躁,也不要直接去百度搜索报错内容, 科学的做法是:看日志-----》锁定问题-----》解决问题

[root@localhost zhanggen]# journalctl -xe
Mar :: localhost.localdomain polkitd[]: Registered Authentication Agent for unix-process:: (system bus name :1.510 [/
Mar :: localhost.localdomain systemd[]: Starting Docker Storage Setup...
-- Subject: Unit docker-storage-setup.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker-storage-setup.service has begun starting up.
Mar :: localhost.localdomain container-storage-setup[]: INFO: Volume group backing root filesystem could not be determined
Mar :: localhost.localdomain systemd[]: Started Docker Storage Setup.
-- Subject: Unit docker-storage-setup.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker-storage-setup.service has finished starting up.
--
-- The start-up result is done.
Mar :: localhost.localdomain systemd[]: Starting Docker Application Container Engine...
-- Subject: Unit docker.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.service has begun starting up.
Mar :: localhost.localdomain dockerd-current[]: unable to configure the Docker daemon with file /etc/docker/daemon.json: inval
Mar :: localhost.localdomain systemd[]: docker.service: main process exited, code=exited, status=/FAILURE
Mar :: localhost.localdomain systemd[]: Failed to start Docker Application Container Engine.
-- Subject: Unit docker.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.service has failed.
--
-- The result is failed.
Mar :: localhost.localdomain systemd[]: Unit docker.service entered failed state.
Mar :: localhost.localdomain systemd[]: docker.service failed.
Mar :: localhost.localdomain polkitd[]: Unregistered Authentication Agent for unix-process:: (system bus name :1.510,

journalctl -xe 查看docker日志

查看docker版本

[root@localhost zhanggen]# docker version
Client:
Version: 1.13.
API version: 1.26
Package version:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

docker version

 

7.docker的组件

docker的组件分为:镜像image、容器container 、仓库(repository)

镜像:所有的docker容器都是由镜像启动构建的

仓库:集中存放镜像,用户同网络访问仓库获得想要镜像 DockerHub,就是GitHub一样;

容器:就是由镜像创建的实例(简化版的Linux环境)

二、docker快速入门

从docker的三大组件开始快速入门docker;

1.docker镜像

去docker Hub 上搜素镜像

[root@localhost zhanggen]# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. [OK]
ansible/centos7-ansible Ansible on Centos7 [OK]
jdeathe/centos-ssh CentOS- 6.10 x86_64 / CentOS- 7.5. x86… [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC session… [OK]
imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 [OK]
centos/mysql--centos7 MySQL 5.7 SQL database server
tutum/centos Simple CentOS docker image with SSH access
gluster/gluster-centos Official GlusterFS Image [ CentOS- + Glust… [OK]
openshift/base-centos7 A Centos7 derived base image for Source-To-I…
centos/postgresql--centos7 PostgreSQL is an advanced Object-Relational …
kinogmt/centos-ssh CentOS with SSH [OK]
centos/httpd--centos7 Platform for running Apache httpd 2.4 or bui…
openshift/jenkins--centos7 A Centos7 based Jenkins v2.x image for use w…
centos/php--centos7 Platform for building and running PHP 5.6 ap…
pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag names…
openshift/wildfly--centos7 A Centos7 based WildFly v10. image for use …
openshift/jenkins--centos7 DEPRECATED: A Centos7 based Jenkins v1.x ima…
darksheer/centos Base Centos Image -- Updated hourly [OK]
pivotaldata/centos-mingw Using the mingw toolchain to cross-compile t…
pivotaldata/centos Base centos, freshened up a little with a Do…
pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated wi…
blacklabelops/centos CentOS Base Image! Built and Updates Daily! [OK]
openshift/wildfly--centos7 A Centos7 based WildFly v8. image for use w…
smartentry/centos centos with smartentry [OK]
jameseckersall/sonarr-centos Sonarr on CentOS

docker search centos

去docker hub上下载镜像

[root@localhost zhanggen]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
8ba884070f61: Pull complete
Digest: sha256:8d487d68857f5bc9595793279b33d082b03713341ddec91054382641d14db861
Status: Downloaded newer image for centos:latest
[root@localhost zhanggen]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 9f38484d220f days ago

docker pull centos

docker镜像保存为文件(镜像导出)

[root@localhost zhanggen]# docker save -o Centos.tart centos
[root@localhost zhanggen]# ls
Centos.tart Desktop Documents Downloads Music Pictures Public Templates Videos

docker save -o Centos.tar

文件还原为docker镜像(镜像导入)

[root@localhost zhanggen]# docker load --input Centos.tar
Loaded image: centos:latest
[root@localhost zhanggen]#

docker load --input Centos.tar

删除docker镜像

[root@localhost zhanggen]# docker rmi -f centos
Untagged: centos:latest
Untagged: centos@sha256:8d487d68857f5bc9595793279b33d082b03713341ddec91054382641d14db861
[root@localhost zhanggen]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 9f38484d220f days ago 202MB
[root@localhost zhanggen]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
Digest: sha256:8d487d68857f5bc9595793279b33d082b03713341ddec91054382641d14db861
Status: Downloaded newer image for centos:latest
[root@localhost zhanggen]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 9f38484d220f days ago 202MB
[root@localhost zhanggen]#

docker rmi -f centos

2.docker容器

镜像的管理就是这些,主要还是自己可以构建镜像

[root@localhost zhanggen]# docker run centos /bin/echo 'hellow I wanna fuck you!!'
WARNING: IPv4 forwarding is disabled. Networking will not work.
hellow I wanna fuck you!!
[root@localhost zhanggen]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost zhanggen]#

docker run centos /bin/echo 'hellow I wanna fuck you!!'

PS:为什么 我运行了一个 echo 程序  docker容器就马上停止了?

因为docker容器默认会在docker容器的前台运行1个进程,这个进程结束docker,容器也随之停止了;(也许这就是它的一次性设计理念吧。。)

是不是很纳闷 为什么docker运行的进程退出,容器怎么就退出了? 这就是docker的理念---不可变基础设施理念!

docker就是给进程做隔离使用的,不同于虚拟机,虚拟机才是给操作系统做隔离使用的;

docker只是个容器 不是虚拟机!

[root@261f12e2d6e4 /]# cat /proc/cpuinfo
processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Core(TM) i7-6500U CPU @ .50GHz
stepping :
microcode : 0x88
cpu MHz : 2591.294
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch arat fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec
bogomips : 5184.39
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management:

你进入容器千万不要感觉是进入了虚拟机

运行新的docker   --name (容器名称) mydocker    -t (terminal 打开一个终端)    -i (std input 打开标准输入 )

[root@localhost zhanggen]# docker run  --name mydocker -t -i centos /bin/bash
WARNING: IPv4 forwarding is disabled. Networking will not work.
[root@261f12e2d6e4 /]#

docker run --name mydocker -t -i centos /bin/bash

启动一个关闭的docker容器

[root@localhost zhanggen]# docker start mydocker
mydocker
[root@localhost zhanggen]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
261f12e2d6e4 centos "/bin/bash" About an hour ago Up seconds mydocker
d0dd5f7a79e8 centos "/bin/echo 'hellow I…" About an hour ago Exited () About an hour ago sharp_chandrasekhar

docker start mydocker

进如正在运行的容器看看

[root@localhost zhanggen]# docker attach mydocker
[root@261f12e2d6e4 /]#

docker attach mydocker

删除正在停止的容器

[root@localhost zhanggen]# docker rm -f e627d59e818c
e627d59e818c
[root@localhost zhanggen]# docker rm -f d0dd5f7a79e8
d0dd5f7a79e8
[root@localhost zhanggen]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost zhanggen]#

docker rm -f e627d59e818c

[root@localhost /]# docker rm $(docker ps -aq)
eecdba33cb61
b2da31fc0100
06afb1402c3e
[root@localhost /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost /]#

docker rm $(docker ps -aq) 一次性删除所有

3.进入正在运行中docker容器的2种最佳方式

查看正在运行容器的进程

[root@localhost zhanggen]# docker inspect -f "{{.State.Pid}}" mydocker

docker inspect -f "{{.State.Pid}}" mydocker

通过进程ID反复进入docker容器

[root@localhost zhanggen]# nsenter -t  -m -u -i -n -p
-bash: __vte_prompt_command: command not found
[root@261f12e2d6e4 /]#

nsenter -t 64721 -m -u -i -n -p

为什么通过 nsenter -t 64721 -m -u -i -n -p 进入docker容器exit之后不退出?

其实就是多开了一个bash进程

[root@localhost zhanggen]# nsenter -t  -m -u -i -n -p
-bash: __vte_prompt_command: command not found
[root@261f12e2d6e4 /]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root : pts/ :: /bin/bash
root : pts/ :: -bash #其实就是多开了1个bash进程
root : pts/ :: ps -ef
-bash: __vte_prompt_command: command not found
[root@261f12e2d6e4 /]# exit
logout
[root@localhost zhanggen]# nsenter -t -m -u -i -p
-bash: __vte_prompt_command: command not found
[root@261f12e2d6e4 /]#

nsenter -t 64721 -m -u -i -n -p

docker exec 在不进入docker容器前提下 执行1个命令(一个程序)

root@localhost zhanggen]# docker exec mydocker whoami
root
[root@localhost zhanggen]# docker exec mydocker pwd
/
[root@localhost zhanggen]# docker exec mydocker ls
anaconda-post.log
bin
dev
etc

docker exec mydocker whoami

通过docker exec 打开bash程序之间进入docker容器

[root@localhost zhanggen]# docker exec -it mydocker /bin/bash
[root@261f12e2d6e4 /]# exit
exit
[root@localhost zhanggen]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 9f38484d220f days ago 202MB
[root@localhost zhanggen]#

docker exec -it mydocker

在宿主机后台运行docker容器

[root@localhost zhanggen]# docker run --name my_nginx -d nginx
WARNING: IPv4 forwarding is disabled. Networking will not work.
3aafe4fe15248ec4cd526a1873b6fc1e50b9c87926f6504755ebd021f76f5d61
[root@localhost zhanggen]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3aafe4fe1524 nginx "nginx -g 'daemon of…" seconds ago Up seconds /tcp my_nginx
[root@localhost zhanggen]#

后台运行docker容器

二、docker的网络访问

As a senior Web application developer,how to access it  if I`ve I developed a  Web application in docker container.

我在docker里面写了个Django程序,我怎么访问它的8001端口呢?这就需要给docker容器开通网络访问功能;

docker安装之后会自动创建一个 docker0的桥接网卡

[root@localhost zhanggen]# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:b4ff:fe4c:7745 prefixlen 64 scopeid 0x20<link>
ether 02:42:b4:4c:77:45 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3 bytes 258 (258.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions

docker0

docker的网络就是通过docker0这个网桥进行 NAT 转换到docker容器的

配置centos7开启IPV4转发并重启网卡

net.ipv4.ip_forward=

vim /usr/lib/sysctl.d/00-system.conf

开启随机端口访问

[root@localhost zhanggen]# vim /usr/lib/sysctl.d/-system.conf
[root@localhost zhanggen]# docker run -d -P nginx
06afb1402c3eb177dbae8b72cd94be90c63713ce73a1bac7ab8f85ecdae50caa
[root@localhost zhanggen]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
06afb1402c3e nginx "nginx -g 'daemon of…" seconds ago Up seconds 0.0.0.0:->/tcp zen_hellman

docker run -d -P nginx

指定端口进行访问

[root@localhost zhanggen]# docker run --name mydocker -d -p : nginx
b2da31fc010033f378e0930a2b77cec498ba6cbc1d288353562e3d0c6b23ae3c
[root@localhost zhanggen]#

docker run --name mydocker -d -p 8001:80 nginx

三、docker的数据管理

说到docker的数据管理,首先得清楚docker镜像的分层存储结构?

docker镜像是采用分层结构存储的,Docker镜像是只读、不可写的,docker容器在docker镜像之上是可写的,用户在docker容器的基础上操作之后commit 修改成只读镜像,盖了一层再来一层....

As I mentioned docker 采用的是一种开箱  既用-->用完--->即仍 的一次性理念,那么在docker运行中产生的一些日志..如何持久化?有一下两种方式;

Docker 容器技术

1.数据卷

我们把宿主机中的一个目录mount 到docker容器的一个目录里面,docker容器运行中产生的数据写得宿主机的目录里;

[root@localhost zhanggen]# docker run -d --name nginx-volume -v /data nginx
70d688ad2c40e4490d05da0fa8bdbc0cc342315f1bbc61e7a63d4422832512c5

docker run -d --name nginx-volume -v /data nginx

如果你想知道docker容器的 /data目录到底挂载到宿主机的哪个目录上了?

[root@localhost zhanggen]# docker run -d --name nginx-volume -v /data nginx
70d688ad2c40e4490d05da0fa8bdbc0cc342315f1bbc61e7a63d4422832512c5
[root@localhost zhanggen]# docker inspect -f {{.Mounts}} nginx-volume
[{volume 4fbd49850452bcca0a867f09776f716b137c5f13f5a8b8a3a5e84e26496f9fcd /var/lib/docker/volumes/4fbd49850452bcca0a867f09776f716b137c5f13f5a8b8a3a5e84e26496f9fcd/_data /data local true }]
[root@localhost zhanggen]# ls
Centos.tart Desktop Documents Downloads Music Pictures Public Templates Videos
[root@localhost zhanggen]# cd /var/lib/docker/volumes/4fbd49850452bcca0a867f09776f716b137c5f13f5a8b8a3a5e84e26496f9fcd/_data
[root@localhost _data]# pwd
/var/lib/docker/volumes/4fbd49850452bcca0a867f09776f716b137c5f13f5a8b8a3a5e84e26496f9fcd/_data
[root@localhost _data]# ls
[root@localhost _data]#

docker run -d --name nginx-volume -v /data nginxdocker & inspect -f {{.Mounts}} nginx-volume

root@localhost _data]# docker inspect -f {{.Mounts}} nginx-volume
[{volume 4fbd49850452bcca0a867f09776f716b137c5f13f5a8b8a3a5e84e26496f9fcd /var/lib/docker/volumes/4fbd49850452bcca0a867f09776f716b137c5f13f5a8b8a3a5e84e26496f9fcd/_data /data local true }]
[root@localhost _data]# pwd
/var/lib/docker/volumes/4fbd49850452bcca0a867f09776f716b137c5f13f5a8b8a3a5e84e26496f9fcd/_data
[root@localhost _data]# touch 草你妈王X聪
[root@localhost _data]# docker exec -it nginx-volume /bin/bash
root@70d688ad2c40:/# ls
bin boot data dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@70d688ad2c40:/# cd d
data/ dev/
root@70d688ad2c40:/# cd data/
root@70d688ad2c40:/data# ls
FUCK_WANGSICHONGTAMA ??????????????????
root@70d688ad2c40:/data#

验证一下docker容器里面的/data目录是否和宿主机的目录关联在一起了

在生产环境我们一般会自己创建一个目录 在挂载到docker目录里

[root@localhost _data]# docker run -d --name nginx-volume -v  /data/docker/volume-nginx/:/data nginx
09fc60548e01040805d6de92ace28062055a91eb832129b075e7e2605c149b45
[root@localhost _data]# docker exec -it nginx-volume /bin/bash
root@09fc60548e01:/# ls
bin boot data dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@09fc60548e01:/# cd data/
root@09fc60548e01:/data# ls
root@09fc60548e01:/data# echo 'sss' > Martin.txt
root@09fc60548e01:/data# ls
Martin.txt
root@09fc60548e01:/data# cat Martin.txt
sss
root@09fc60548e01:/data# exit
exit
[root@localhost _data]# pwd
/var/lib/docker/volumes/4fbd49850452bcca0a867f09776f716b137c5f13f5a8b8a3a5e84e26496f9fcd/_data
[root@localhost _data]# cd /data/docker/volume-nginx/
[root@localhost volume-nginx]# ls
Martin.txt
[root@localhost volume-nginx]# cat Martin.txt
sss
[root@localhost volume-nginx]#

docker run -d --name nginx-volume -v /data/docker/volume-nginx/:/data nginx

 2.数据卷容器

在容器是否运行、关闭的状态下,容器之间都可以共享容器卷数据;(NFS)

使用--volumes-from 指定要和哪个容器共享容器卷

[root@localhost volume-nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09fc60548e01 nginx "nginx -g 'daemon of…" minutes ago Up minutes /tcp nginx-volume
[root@localhost volume-nginx]# docker run -it --name volume-test --volumes-from nginx-volume centos /bin/bash
[root@c16407be0cf4 /]# ls data/
Martin.txt
[root@c16407be0cf4 /]# exit
exit
[root@localhost volume-nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09fc60548e01 nginx "nginx -g 'daemon of…" minutes ago Up minutes /tcp nginx-volume
[root@localhost volume-nginx]# docker exec -it nginx-volume /bin/bash
root@09fc60548e01:/# ls data/
Martin.txt
root@09fc60548e01:/#

docker run -it --name volume-test --volumes-from nginx-volume centos /bin/bash

生成环境:一般都会起 1个专门的容器挂载到宿主机的1个目录上,以后其他容器都 通过 --volumes-from 该容器   的形式来达到容器卷数据共享的效果;

四、docker镜像的构建

docker镜像是docker可以传播的介质,那么如何制作自己的docker镜像?分为如下2种方式:

手动构建

自己在容器里面做操作,操作完毕之后,commit成自己的镜像,

Dockerfile构建

以文件的形式执行力里面的命令进行快速构建,比较自动化化,相比容器较为轻量也更易于传播;

最后还会谈谈我在生产环境中使用dockerfile的经验。

Docker 容器技术

1.手动创建镜像

docker run --name mynginx -it centos    #使用基础镜像 centos 运行1个名为 mynginx 的容器
vim /etc/nginx/nginx.conf 进入docker容器,修改Nginx配置文件

exit 退出容器

docker ps -a                                 #查看刚刚exit的容器
docker commit -m 'MyNginx' cd35 zhanggen/mynginx:v1              #commit把停止的容器提交到本地分支
docker images                                                     #制作完成
docker run --name mynginxv1 -d -p : zhanggen/mynginx:v1 nginx #启动

PS:麻蛋发现自己制作的docker镜像启动不起来咋办?

查看容器启动的报错日志----》重新进入容器-----》检查操作,修改---》重新提交本地分支-----》重新启动

docker ps -a                                   #查看启动失败的镜像ID
docker logs container_id #查看报错日志
docker run -it zhanggen/mynginx:v1 /bin/bash #重新运行 该镜像进去修改
docker commit -m 'MyNginx' cd35 zhanggen/mynginx:v1 #修改完毕重新提交到本地分支
docker run --name mynginxv1 -d -p : zhanggen/mynginx:v1 nginx #重新启动镜像

自制镜像无法启动攻略

2.Docker file构建

Docker file语法

Docker 容器技术

Docker 容器技术

OM centos
MAINTAINER Martin.Zhang
RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
RUN yum install -y nginx && yum clean all
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
ADD index.html /usr/share/nginx/html/index.html
EXPOSE
CMD ["nginx"]

Dockerfile

<html>
<body>
<h1>ssssssssss!!!!</h1>
</body>
</html>

index.html

[root@localhost nginx]# pwd
/dockerfile/nginx
[root@localhost nginx]# ls
Dockerfile index.html
[root@localhost nginx]# docker build -t mynginx:v2 .
Sending build context to Docker daemon .072kB
Step / : FROM centos
---> 9f38484d220f
Step / : MAINTAINER Martin.Zhang
---> Running in be6d86ffa2a9
Removing intermediate container be6d86ffa2a9
---> 0dc16c8dadcc
Step / : RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
---> Running in 3ce6b480a0a2
warning: /var/tmp/rpm-tmp.qHH8Wh: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Retrieving http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
Preparing... ########################################
Updating / installing...
epel-release-- ########################################
Removing intermediate container 3ce6b480a0a2
---> 6b2b42a8e360
Step / : RUN yum install -y nginx && yum clean all
---> Running in 3e228aab6696
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 :1.12.-.el7 will be installed
--> Processing Dependency: nginx-all-modules = :1.12.-.el7 for package: :nginx-1.12.-.el7.x86_64
--> Processing Dependency: nginx-filesystem = :1.12.-.el7 for package: :nginx-1.12.-.el7.x86_64
--> Processing Dependency: nginx-filesystem for package: :nginx-1.12.-.el7.x86_64
--> Processing Dependency: openssl for package: :nginx-1.12.-.el7.x86_64
--> Processing Dependency: libprofiler.so.()(64bit) for package: :nginx-1.12.-.el7.x86_64
--> Running transaction check
---> Package gperftools-libs.x86_64 :2.6.-.el7 will be installed
---> Package nginx-all-modules.noarch :1.12.-.el7 will be installed
--> Processing Dependency: nginx-mod-http-geoip = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
--> Processing Dependency: nginx-mod-http-image-filter = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
--> Processing Dependency: nginx-mod-http-perl = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
--> Processing Dependency: nginx-mod-http-xslt-filter = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
--> Processing Dependency: nginx-mod-mail = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
--> Processing Dependency: nginx-mod-stream = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
---> Package nginx-filesystem.noarch :1.12.-.el7 will be installed
---> Package openssl.x86_64 :1.0.2k-.el7_6. will be installed
--> Processing Dependency: openssl-libs(x86-) = :1.0.2k-.el7_6. for package: :openssl-1.0.2k-.el7_6..x86_64
--> Processing Dependency: make for package: :openssl-1.0.2k-.el7_6..x86_64
--> Running transaction check
---> Package make.x86_64 :3.82-.el7 will be installed
---> Package nginx-mod-http-geoip.x86_64 :1.12.-.el7 will be installed
--> Processing Dependency: GeoIP for package: :nginx-mod-http-geoip-1.12.-.el7.x86_64
--> Processing Dependency: libGeoIP.so.()(64bit) for package: :nginx-mod-http-geoip-1.12.-.el7.x86_64
---> Package nginx-mod-http-image-filter.x86_64 :1.12.-.el7 will be installed
--> Processing Dependency: gd for package: :nginx-mod-http-image-filter-1.12.-.el7.x86_64
--> Processing Dependency: libgd.so.()(64bit) for package: :nginx-mod-http-image-filter-1.12.-.el7.x86_64
---> Package nginx-mod-http-perl.x86_64 :1.12.-.el7 will be installed
--> Processing Dependency: perl >= 5.006001 for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(:MODULE_COMPAT_5.16.3) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(Exporter) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(XSLoader) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(constant) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(strict) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(warnings) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: libperl.so()(64bit) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
---> Package nginx-mod-http-xslt-filter.x86_64 :1.12.-.el7 will be installed
--> Processing Dependency: libxslt.so.(LIBXML2_1.0.11)(64bit) for package: :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64
--> Processing Dependency: libxslt.so.(LIBXML2_1.0.18)(64bit) for package: :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64
--> Processing Dependency: libexslt.so.()(64bit) for package: :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64
--> Processing Dependency: libxslt.so.()(64bit) for package: :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64
---> Package nginx-mod-mail.x86_64 :1.12.-.el7 will be installed
---> Package nginx-mod-stream.x86_64 :1.12.-.el7 will be installed
---> Package openssl-libs.x86_64 :1.0.2k-.el7 will be updated
---> Package openssl-libs.x86_64 :1.0.2k-.el7_6. will be an update
--> Running transaction check
---> Package GeoIP.x86_64 :1.5.-.el7 will be installed
---> Package gd.x86_64 :2.0.-.el7 will be installed
--> Processing Dependency: libpng15.so.(PNG15_0)(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libjpeg.so.(LIBJPEG_6.)(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libpng15.so.()(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libjpeg.so.()(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libfreetype.so.()(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libfontconfig.so.()(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libXpm.so.()(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libX11.so.()(64bit) for package: gd-2.0.-.el7.x86_64
---> Package libxslt.x86_64 :1.1.-.el7 will be installed
---> Package perl.x86_64 :5.16.-.el7_6 will be installed
--> Processing Dependency: perl(Socket) >= 1.3 for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl-macros for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(threads::shared) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(threads) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Time::Local) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Time::HiRes) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Storable) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Socket) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Scalar::Util) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Pod::Simple::XHTML) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Pod::Simple::Search) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Getopt::Long) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Filter::Util::Call) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(File::Temp) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(File::Spec::Unix) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(File::Spec::Functions) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(File::Spec) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(File::Path) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Cwd) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Carp) for package: :perl-5.16.-.el7_6.x86_64
---> Package perl-Exporter.noarch :5.68-.el7 will be installed
---> Package perl-constant.noarch :1.27-.el7 will be installed
---> Package perl-libs.x86_64 :5.16.-.el7_6 will be installed
--> Running transaction check
---> Package fontconfig.x86_64 :2.13.-4.3.el7 will be installed
--> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.13.-4.3.el7.x86_64
--> Processing Dependency: dejavu-sans-fonts for package: fontconfig-2.13.-4.3.el7.x86_64
---> Package freetype.x86_64 :2.8-.el7_6. will be installed
---> Package libX11.x86_64 :1.6.-.el7 will be installed
--> Processing Dependency: libX11-common >= 1.6.-.el7 for package: libX11-1.6.-.el7.x86_64
--> Processing Dependency: libxcb.so.()(64bit) for package: libX11-1.6.-.el7.x86_64
---> Package libXpm.x86_64 :3.5.-.el7 will be installed
---> Package libjpeg-turbo.x86_64 :1.2.-.el7 will be installed
---> Package libpng.x86_64 :1.5.-.el7_2 will be installed
---> Package perl-Carp.noarch :1.26-.el7 will be installed
---> Package perl-File-Path.noarch :2.09-.el7 will be installed
---> Package perl-File-Temp.noarch :0.23.-.el7 will be installed
---> Package perl-Filter.x86_64 :1.49-.el7 will be installed
---> Package perl-Getopt-Long.noarch :2.40-.el7 will be installed
--> Processing Dependency: perl(Pod::Usage) >= 1.14 for package: perl-Getopt-Long-2.40-.el7.noarch
--> Processing Dependency: perl(Text::ParseWords) for package: perl-Getopt-Long-2.40-.el7.noarch
---> Package perl-PathTools.x86_64 :3.40-.el7 will be installed
---> Package perl-Pod-Simple.noarch :3.28-.el7 will be installed
--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: :perl-Pod-Simple-3.28-.el7.noarch
--> Processing Dependency: perl(Encode) for package: :perl-Pod-Simple-3.28-.el7.noarch
---> Package perl-Scalar-List-Utils.x86_64 :1.27-.el7 will be installed
---> Package perl-Socket.x86_64 :2.010-.el7 will be installed
---> Package perl-Storable.x86_64 :2.45-.el7 will be installed
---> Package perl-Time-HiRes.x86_64 :1.9725-.el7 will be installed
---> Package perl-Time-Local.noarch :1.2300-.el7 will be installed
---> Package perl-macros.x86_64 :5.16.-.el7_6 will be installed
---> Package perl-threads.x86_64 :1.87-.el7 will be installed
---> Package perl-threads-shared.x86_64 :1.43-.el7 will be installed
--> Running transaction check
---> Package dejavu-sans-fonts.noarch :2.33-.el7 will be installed
--> Processing Dependency: dejavu-fonts-common = 2.33-.el7 for package: dejavu-sans-fonts-2.33-.el7.noarch
---> Package fontpackages-filesystem.noarch :1.44-.el7 will be installed
---> Package libX11-common.noarch :1.6.-.el7 will be installed
---> Package libxcb.x86_64 :1.13-.el7 will be installed
--> Processing Dependency: libXau.so.()(64bit) for package: libxcb-1.13-.el7.x86_64
---> Package perl-Encode.x86_64 :2.51-.el7 will be installed
---> Package perl-Pod-Escapes.noarch :1.04-.el7_6 will be installed
---> Package perl-Pod-Usage.noarch :1.63-.el7 will be installed
--> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-.el7.noarch
--> Processing Dependency: perl-Pod-Perldoc for package: perl-Pod-Usage-1.63-.el7.noarch
---> Package perl-Text-ParseWords.noarch :3.29-.el7 will be installed
--> Running transaction check
---> Package dejavu-fonts-common.noarch :2.33-.el7 will be installed
---> Package libXau.x86_64 :1.0.-2.1.el7 will be installed
---> Package perl-Pod-Perldoc.noarch :3.20-.el7 will be installed
--> Processing Dependency: perl(parent) for package: perl-Pod-Perldoc-3.20-.el7.noarch
--> Processing Dependency: perl(HTTP::Tiny) for package: perl-Pod-Perldoc-3.20-.el7.noarch
--> Processing Dependency: groff-base for package: perl-Pod-Perldoc-3.20-.el7.noarch
---> Package perl-podlators.noarch :2.5.-.el7 will be installed
--> Running transaction check
---> Package groff-base.x86_64 :1.22.-.el7 will be installed
---> Package perl-HTTP-Tiny.noarch :0.033-.el7 will be installed
---> Package perl-parent.noarch :0.225-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ================================================================================
Package Arch Version Repository
Size
================================================================================
Installing:
nginx x86_64 :1.12.-.el7 epel k
Installing for dependencies:
GeoIP x86_64 1.5.-.el7 base 1.5 M
dejavu-fonts-common noarch 2.33-.el7 base k
dejavu-sans-fonts noarch 2.33-.el7 base 1.4 M
fontconfig x86_64 2.13.-4.3.el7 base k
fontpackages-filesystem noarch 1.44-.el7 base 9.9 k
freetype x86_64 2.8-.el7_6. updates k
gd x86_64 2.0.-.el7 base k
gperftools-libs x86_64 2.6.-.el7 base k
groff-base x86_64 1.22.-.el7 base k
libX11 x86_64 1.6.-.el7 base k
libX11-common noarch 1.6.-.el7 base k
libXau x86_64 1.0.-2.1.el7 base k
libXpm x86_64 3.5.-.el7 base k
libjpeg-turbo x86_64 1.2.-.el7 base k
libpng x86_64 :1.5.-.el7_2 base k
libxcb x86_64 1.13-.el7 base k
libxslt x86_64 1.1.-.el7 base k
make x86_64 :3.82-.el7 base k
nginx-all-modules noarch :1.12.-.el7 epel k
nginx-filesystem noarch :1.12.-.el7 epel k
nginx-mod-http-geoip x86_64 :1.12.-.el7 epel k
nginx-mod-http-image-filter x86_64 :1.12.-.el7 epel k
nginx-mod-http-perl x86_64 :1.12.-.el7 epel k
nginx-mod-http-xslt-filter x86_64 :1.12.-.el7 epel k
nginx-mod-mail x86_64 :1.12.-.el7 epel k
nginx-mod-stream x86_64 :1.12.-.el7 epel k
openssl x86_64 :1.0.2k-.el7_6. updates k
perl x86_64 :5.16.-.el7_6 updates 8.0 M
perl-Carp noarch 1.26-.el7 base k
perl-Encode x86_64 2.51-.el7 base 1.5 M
perl-Exporter noarch 5.68-.el7 base k
perl-File-Path noarch 2.09-.el7 base k
perl-File-Temp noarch 0.23.-.el7 base k
perl-Filter x86_64 1.49-.el7 base k
perl-Getopt-Long noarch 2.40-.el7 base k
perl-HTTP-Tiny noarch 0.033-.el7 base k
perl-PathTools x86_64 3.40-.el7 base k
perl-Pod-Escapes noarch :1.04-.el7_6 updates k
perl-Pod-Perldoc noarch 3.20-.el7 base k
perl-Pod-Simple noarch :3.28-.el7 base k
perl-Pod-Usage noarch 1.63-.el7 base k
perl-Scalar-List-Utils x86_64 1.27-.el7 base k
perl-Socket x86_64 2.010-.el7 base k
perl-Storable x86_64 2.45-.el7 base k
perl-Text-ParseWords noarch 3.29-.el7 base k
perl-Time-HiRes x86_64 :1.9725-.el7 base k
perl-Time-Local noarch 1.2300-.el7 base k
perl-constant noarch 1.27-.el7 base k
perl-libs x86_64 :5.16.-.el7_6 updates k
perl-macros x86_64 :5.16.-.el7_6 updates k
perl-parent noarch :0.225-.el7 base k
perl-podlators noarch 2.5.-.el7 base k
perl-threads x86_64 1.87-.el7 base k
perl-threads-shared x86_64 1.43-.el7 base k
Updating for dependencies:
openssl-libs x86_64 :1.0.2k-.el7_6. updates 1.2 M Transaction Summary
================================================================================
Install Package (+ Dependent packages)
Upgrade ( Dependent package) Total download size: M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64//base/packages/fontpackages-filesystem-1.44-.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for fontpackages-filesystem-1.44-.el7.noarch.rpm is not installed
Public key for freetype-2.8-.el7_6..x86_64.rpm is not installed
warning: /var/cache/yum/x86_64//epel/packages/nginx-all-modules-1.12.-.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for nginx-all-modules-1.12.-.el7.noarch.rpm is not installed
--------------------------------------------------------------------------------
Total kB/s | MB :
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release--6.1810..el7.centos.x86_64 (@CentOS)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
Userid : "Fedora EPEL (7) <epel@fedoraproject.org>"
Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
Package : epel-release--.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Updating : :openssl-libs-1.0.2k-.el7_6..x86_64 /
Installing : fontpackages-filesystem-1.44-.el7.noarch /
Installing : :libpng-1.5.-.el7_2.x86_64 /
Installing : freetype-2.8-.el7_6..x86_64 /
Installing : dejavu-fonts-common-2.33-.el7.noarch /
Installing : dejavu-sans-fonts-2.33-.el7.noarch /
Installing : fontconfig-2.13.-4.3.el7.x86_64 /
Installing : :make-3.82-.el7.x86_64 /
Installing : :openssl-1.0.2k-.el7_6..x86_64 /
Installing : libX11-common-1.6.-.el7.noarch /
Installing : gperftools-libs-2.6.-.el7.x86_64 /
Installing : libXau-1.0.-2.1.el7.x86_64 /
Installing : libxcb-1.13-.el7.x86_64 /
Installing : libX11-1.6.-.el7.x86_64 /
Installing : libXpm-3.5.-.el7.x86_64 /
Installing : libxslt-1.1.-.el7.x86_64 /
Installing : :nginx-filesystem-1.12.-.el7.noarch /
Installing : GeoIP-1.5.-.el7.x86_64 /
Installing : libjpeg-turbo-1.2.-.el7.x86_64 /
Installing : gd-2.0.-.el7.x86_64 /
Installing : groff-base-1.22.-.el7.x86_64 /
Installing : :perl-parent-0.225-.el7.noarch /
Installing : perl-HTTP-Tiny-0.033-.el7.noarch /
Installing : perl-podlators-2.5.-.el7.noarch /
Installing : perl-Pod-Perldoc-3.20-.el7.noarch /
Installing : perl-Encode-2.51-.el7.x86_64 /
Installing : perl-Text-ParseWords-3.29-.el7.noarch /
Installing : :perl-Pod-Escapes-1.04-.el7_6.noarch /
Installing : perl-Pod-Usage-1.63-.el7.noarch /
Installing : :perl-libs-5.16.-.el7_6.x86_64 /
Installing : :perl-macros-5.16.-.el7_6.x86_64 /
Installing : :perl-Time-HiRes-1.9725-.el7.x86_64 /
Installing : perl-Exporter-5.68-.el7.noarch /
Installing : perl-constant-1.27-.el7.noarch /
Installing : perl-Time-Local-1.2300-.el7.noarch /
Installing : perl-Carp-1.26-.el7.noarch /
Installing : perl-Storable-2.45-.el7.x86_64 /
Installing : perl-PathTools-3.40-.el7.x86_64 /
Installing : perl-Scalar-List-Utils-1.27-.el7.x86_64 /
Installing : :perl-Pod-Simple-3.28-.el7.noarch /
Installing : perl-File-Temp-0.23.-.el7.noarch /
Installing : perl-File-Path-2.09-.el7.noarch /
Installing : perl-threads-shared-1.43-.el7.x86_64 /
Installing : perl-threads-1.87-.el7.x86_64 /
Installing : perl-Filter-1.49-.el7.x86_64 /
Installing : perl-Socket-2.010-.el7.x86_64 /
Installing : perl-Getopt-Long-2.40-.el7.noarch /
Installing : :perl-5.16.-.el7_6.x86_64 /
Installing : :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64 /
Installing : :nginx-mod-http-geoip-1.12.-.el7.x86_64 /
Installing : :nginx-mod-stream-1.12.-.el7.x86_64 /
Installing : :nginx-mod-mail-1.12.-.el7.x86_64 /
Installing : :nginx-mod-http-image-filter-1.12.-.el7.x86_64 /
Installing : :nginx-1.12.-.el7.x86_64 /
Installing : :nginx-mod-http-perl-1.12.-.el7.x86_64 /
Installing : :nginx-all-modules-1.12.-.el7.noarch /
Cleanup : :openssl-libs-1.0.2k-.el7.x86_64 /
Verifying : perl-HTTP-Tiny-0.033-.el7.noarch /
Verifying : fontconfig-2.13.-4.3.el7.x86_64 /
Verifying : :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64 /
Verifying : perl-threads-shared-1.43-.el7.x86_64 /
Verifying : :perl-Time-HiRes-1.9725-.el7.x86_64 /
Verifying : :nginx-mod-http-geoip-1.12.-.el7.x86_64 /
Verifying : groff-base-1.22.-.el7.x86_64 /
Verifying : perl-Exporter-5.68-.el7.noarch /
Verifying : perl-constant-1.27-.el7.noarch /
Verifying : perl-PathTools-3.40-.el7.x86_64 /
Verifying : :libpng-1.5.-.el7_2.x86_64 /
Verifying : dejavu-fonts-common-2.33-.el7.noarch /
Verifying : fontpackages-filesystem-1.44-.el7.noarch /
Verifying : :nginx-mod-stream-1.12.-.el7.x86_64 /
Verifying : libjpeg-turbo-1.2.-.el7.x86_64 /
Verifying : :perl-parent-0.225-.el7.noarch /
Verifying : GeoIP-1.5.-.el7.x86_64 /
Verifying : :perl-libs-5.16.-.el7_6.x86_64 /
Verifying : perl-Encode-2.51-.el7.x86_64 /
Verifying : perl-File-Temp-0.23.-.el7.noarch /
Verifying : :perl-Pod-Simple-3.28-.el7.noarch /
Verifying : perl-Getopt-Long-2.40-.el7.noarch /
Verifying : :nginx-all-modules-1.12.-.el7.noarch /
Verifying : libxcb-1.13-.el7.x86_64 /
Verifying : perl-Time-Local-1.2300-.el7.noarch /
Verifying : :perl-macros-5.16.-.el7_6.x86_64 /
Verifying : :perl-5.16.-.el7_6.x86_64 /
Verifying : libXpm-3.5.-.el7.x86_64 /
Verifying : perl-Text-ParseWords-3.29-.el7.noarch /
Verifying : :openssl-1.0.2k-.el7_6..x86_64 /
Verifying : :nginx-filesystem-1.12.-.el7.noarch /
Verifying : perl-Carp-1.26-.el7.noarch /
Verifying : libxslt-1.1.-.el7.x86_64 /
Verifying : libX11-1.6.-.el7.x86_64 /
Verifying : perl-Storable-2.45-.el7.x86_64 /
Verifying : dejavu-sans-fonts-2.33-.el7.noarch /
Verifying : :nginx-mod-mail-1.12.-.el7.x86_64 /
Verifying : perl-Scalar-List-Utils-1.27-.el7.x86_64 /
Verifying : gd-2.0.-.el7.x86_64 /
Verifying : :perl-Pod-Escapes-1.04-.el7_6.noarch /
Verifying : :nginx-mod-http-image-filter-1.12.-.el7.x86_64 /
Verifying : perl-Pod-Usage-1.63-.el7.noarch /
Verifying : :openssl-libs-1.0.2k-.el7_6..x86_64 /
Verifying : :nginx-1.12.-.el7.x86_64 /
Verifying : perl-Pod-Perldoc-3.20-.el7.noarch /
Verifying : perl-podlators-2.5.-.el7.noarch /
Verifying : libXau-1.0.-2.1.el7.x86_64 /
Verifying : perl-File-Path-2.09-.el7.noarch /
Verifying : perl-threads-1.87-.el7.x86_64 /
Verifying : gperftools-libs-2.6.-.el7.x86_64 /
Verifying : libX11-common-1.6.-.el7.noarch /
Verifying : perl-Filter-1.49-.el7.x86_64 /
Verifying : freetype-2.8-.el7_6..x86_64 /
Verifying : :nginx-mod-http-perl-1.12.-.el7.x86_64 /
Verifying : perl-Socket-2.010-.el7.x86_64 /
Verifying : :make-3.82-.el7.x86_64 /
Verifying : :openssl-libs-1.0.2k-.el7.x86_64 / Installed:
nginx.x86_64 :1.12.-.el7 Dependency Installed:
GeoIP.x86_64 :1.5.-.el7
dejavu-fonts-common.noarch :2.33-.el7
dejavu-sans-fonts.noarch :2.33-.el7
fontconfig.x86_64 :2.13.-4.3.el7
fontpackages-filesystem.noarch :1.44-.el7
freetype.x86_64 :2.8-.el7_6.
gd.x86_64 :2.0.-.el7
gperftools-libs.x86_64 :2.6.-.el7
groff-base.x86_64 :1.22.-.el7
libX11.x86_64 :1.6.-.el7
libX11-common.noarch :1.6.-.el7
libXau.x86_64 :1.0.-2.1.el7
libXpm.x86_64 :3.5.-.el7
libjpeg-turbo.x86_64 :1.2.-.el7
libpng.x86_64 :1.5.-.el7_2
libxcb.x86_64 :1.13-.el7
libxslt.x86_64 :1.1.-.el7
make.x86_64 :3.82-.el7
nginx-all-modules.noarch :1.12.-.el7
nginx-filesystem.noarch :1.12.-.el7
nginx-mod-http-geoip.x86_64 :1.12.-.el7
nginx-mod-http-image-filter.x86_64 :1.12.-.el7
nginx-mod-http-perl.x86_64 :1.12.-.el7
nginx-mod-http-xslt-filter.x86_64 :1.12.-.el7
nginx-mod-mail.x86_64 :1.12.-.el7
nginx-mod-stream.x86_64 :1.12.-.el7
openssl.x86_64 :1.0.2k-.el7_6.
perl.x86_64 :5.16.-.el7_6
perl-Carp.noarch :1.26-.el7
perl-Encode.x86_64 :2.51-.el7
perl-Exporter.noarch :5.68-.el7
perl-File-Path.noarch :2.09-.el7
perl-File-Temp.noarch :0.23.-.el7
perl-Filter.x86_64 :1.49-.el7
perl-Getopt-Long.noarch :2.40-.el7
perl-HTTP-Tiny.noarch :0.033-.el7
perl-PathTools.x86_64 :3.40-.el7
perl-Pod-Escapes.noarch :1.04-.el7_6
perl-Pod-Perldoc.noarch :3.20-.el7
perl-Pod-Simple.noarch :3.28-.el7
perl-Pod-Usage.noarch :1.63-.el7
perl-Scalar-List-Utils.x86_64 :1.27-.el7
perl-Socket.x86_64 :2.010-.el7
perl-Storable.x86_64 :2.45-.el7
perl-Text-ParseWords.noarch :3.29-.el7
perl-Time-HiRes.x86_64 :1.9725-.el7
perl-Time-Local.noarch :1.2300-.el7
perl-constant.noarch :1.27-.el7
perl-libs.x86_64 :5.16.-.el7_6
perl-macros.x86_64 :5.16.-.el7_6
perl-parent.noarch :0.225-.el7
perl-podlators.noarch :2.5.-.el7
perl-threads.x86_64 :1.87-.el7
perl-threads-shared.x86_64 :1.43-.el7 Dependency Updated:
openssl-libs.x86_64 :1.0.2k-.el7_6. Complete!
Loaded plugins: fastestmirror, ovl
Cleaning repos: base epel extras updates
Cleaning up list of fastest mirrors
Removing intermediate container 3e228aab6696
---> d31beb8cce1e
Step / : RUN echo "daemon off;" >> /etc/nginx/nginx.conf
---> Running in e2770ee72af0
Removing intermediate container e2770ee72af0
---> 56382e656884
Step / : ADD index.html /usr/share/nginx/html/index.html
---> 9a268246ca18
Step / : EXPOSE
---> Running in 92412b2bb046
Removing intermediate container 92412b2bb046
---> 05ce68ba1519
Step / : CMD ["nginx"]
---> Running in fa9037b49675
Removing intermediate container fa9037b49675
---> 5aee9f4c1ada
Successfully built 5aee9f4c1ada
Successfully tagged mynginx:v2
[root@localhost nginx]# docker image Usage: docker image COMMAND Manage images Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE Run 'docker image COMMAND --help' for more information on a command.
[root@localhost nginx]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx v2 5aee9f4c1ada seconds ago 307MB
centos latest 9f38484d220f days ago 202MB
nginx latest 881bd08c0b08 weeks ago 109MB
[root@localhost nginx]#

docker build -t mynginx:v2 .

启动镜像

[root@localhost nginx]# cat index.html
<html>
<body>
<h1>首页!!!!</h1>
</body>
</html>
[root@localhost nginx]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx v2 5aee9f4c1ada 4 minutes ago 307MB
centos latest 9f38484d220f 10 days ago 202MB
nginx latest 881bd08c0b08 2 weeks ago 109MB
[root@localhost nginx]# docker run --name mynginxv2 -d -p 81:80 mynginx:v2 nginx
8e269403c1b4181dd187eb20c74eb465f5f165ce0bfbc9b444d57164b1621e24
[root@localhost nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8e269403c1b4 mynginx:v2 "nginx" 4 seconds ago Up 3 seconds 0.0.0.0:81->80/tcp mynginxv2
[root@localhost nginx]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:86:32:27 brd ff:ff:ff:ff:ff:ff
inet 192.168.226.159/24 brd 192.168.226.255 scope global dynamic ens33
valid_lft 1636sec preferred_lft 1636sec
inet6 fe80::6f1c:2b48:af8b:a03a/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
link/ether 52:54:00:31:bf:a8 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
link/ether 52:54:00:31:bf:a8 brd ff:ff:ff:ff:ff:ff
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 02:42:b4:4c:77:45 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:b4ff:fe4c:7745/64 scope link
valid_lft forever preferred_lft forever
79: veth3778ee4@if78: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP
link/ether d2:b8:51:47:0d:1d brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::d0b8:51ff:fe47:d1d/64 scope link
valid_lft forever preferred_lft forever
[root@localhost nginx]# curl 192.168.226.159:81
<html>
<body>
<h1>首页!!!!</h1>
</body>
</html>
[root@localhost nginx]# docker run --name mynginxv2 -d -p 81:80 mynginx:v2 nginx

docker run --name mynginxv2 -d -p 81:80 mynginx:v2 nginx

五、docker file生产实践

docker file go live

1.目录环境准备

[root@localhost docker_image]# ls
apps runtime system
[root@localhost docker_image]# tree
.
├── apps
│   └── work_order_api
├── runtime
│   ├── java
│   ├── php
│   └── python
└── system
├── centos
└── centos-ssh

在架构设计里面有个分层设计的理念,我们也可把生产环境分为:系统层、运行环境层、业务层,这也迎合了docker镜像的分层,

Linux系统: centos、Ubuntu....

运行环境: Java 、Python 、PHP.....

App:API、WebAPP、BackGroundManagement ...

Docker file最大的亮点在于FROM,有了它就可以基于不同的镜像,衍生出多种镜像,就和搭积木类似,分好层 可以灵活组装就好。

2.系统环境层docker file (centos7)

下载epel.repo源文件

[root@localhost centos]# pwd
/docker_image/system/centos
[root@localhost centos]# wget -O ./epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
---- ::-- http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 175.6.29.211, 175.6.29.218, 175.6.29.213, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|175.6.29.211|:... connected.
HTTP request sent, awaiting response... OK
Length: [application/octet-stream]
Saving to: ‘./epel.repo’ %[==================================================================================================>] --.-K/s in 0s -- :: ( MB/s) - ‘./epel.repo’ saved [/] [root@localhost centos]# ls
epel.repo

wget -O ./epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

FROM centos
MAINTAINER zhanggen
ADD epel.repo /etc/yum.repos.d/
run yum install -y wget mysql-devel supervisor git redis tree net-toos sudo psmisc && yum clean all

Dockerfile

[root@localhost centos]# ls
Dockerfile epel.repo
[root@localhost centos]# docker build -t zhanggen/centos:v1 .

docker build -t zhanggen/centos:v1 .

3.开发环境层docker file (Python3.6.1)

[root@localhost python]# pwd
/docker_image/runtime/python
[root@localhost python]# ls
Dockerfile Python-3.6..tgz
[root@localhost python]#
FROM zhanggen/centos:v1

MAINTAINER Gen.Zhang

RUN yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel gcc automake autoconf libtool make db4-devel libpcap-devel xz-devel

RUN yum clean all

ADD Python-3.6..tgz /python_packages/

RUN mkdir -p /zhanggen/python3.6.1

RUN cd /python_packages/Python-3.6. && ./configure --prefix=/zhanggen/python3.6.1 && make && make install

RUN echo -e "PATH=$PATH:$HOME/bin:/zhanggen/python3.6.1/bin \n export PATH" > /etc/profile.d/python3.6.1.sh && source /etc/profile.d/python3.6.1.sh

Dockerfile

构建python开发环境镜像

[root@localhost runtime]# cd python/
[root@localhost python]# ls
Dockerfile Python-3.6..tgz
[root@localhost python]# docker build -t zhanggen/python3.6.1:v1 .
Sending build context to Docker daemon .54MB
Step / : FROM zhanggen/centos:v1
---> 9c10a3b17a66
Step / : MAINTAINER Gen.Zhang
---> Using cache
---> 4c630636d1f9
Step / : RUN yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel gcc automake autoconf libtool make db4-devel libpcap-devel xz-devel
---> Using cache
---> ff12b7d7dbd3
Step / : RUN yum clean all
---> Using cache
---> 32c615445b0a
Step / : ADD Python-3.6..tgz /python_packages/
---> Using cache
---> ac70242e584b
Step / : RUN mkdir -p /zhanggen/python3.6.1
---> Using cache
---> 426627a6cb1f
Step / : RUN cd /python_packages/Python-3.6. && ./configure --prefix=/zhanggen/python3.6.1 && make && make install
---> Using cache
---> d15daa242a06
Step / : RUN echo -e "PATH=$PATH:$HOME/bin:/zhanggen/python3.6.1/bin \n export PATH" > /etc/profile.d/python3.6.1.sh && source /etc/profile.d/python3.6.1.sh
---> Using cache
---> 20e32f2fde08
Successfully built 20e32f2fde08
Successfully tagged zhanggen/python3.6.1:v1
[root@localhost python]# docker build -t zhanggen/python3.6.1:v1 .
Sending build context to Docker daemon .54MB
Step / : FROM zhanggen/centos:v1
---> 9c10a3b17a66
Step / : MAINTAINER Gen.Zhang
---> Using cache
---> 4c630636d1f9
Step / : RUN yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel gcc automake autoconf libtool make db4-devel libpcap-devel xz-devel
---> Using cache
---> ff12b7d7dbd3
Step / : RUN yum clean all
---> Using cache
---> 32c615445b0a
Step / : ADD Python-3.6..tgz /python_packages/
---> Using cache
---> ac70242e584b
Step / : RUN mkdir -p /zhanggen/python3.6.1
---> Using cache
---> 426627a6cb1f
Step / : RUN cd /python_packages/Python-3.6. && ./configure --prefix=/zhanggen/python3.6.1 && make && make install
---> Using cache
---> d15daa242a06
Step / : RUN echo -e "PATH=$PATH:$HOME/bin:/zhanggen/python3.6.1/bin \n export PATH" > /etc/profile.d/python3.6.1.sh && source /etc/profile.d/python3.6.1.sh
---> Using cache
---> 20e32f2fde08
Successfully built 20e32f2fde08
Successfully tagged zhanggen/python3.6.1:v1
[root@localhost python]# pwd
/docker_image/runtime/python

docker build -t zhanggen/python3.6.1:v1 .

4、APP层 docker file(Django web app)

Docker容器只允许在前台 运行1个进程,我们如何破解?

Supervisor是Python开发的进程管理工具,可以同时开启、重启、关闭多个进程,可以启动1个Supervisor进程使用Supercisor启动、管理N个进程;

我发现Supervisor不仅可以统一管理进程,还可以规范进程的日志路径,规范了日志路径之后,就可以很方便得找得这些日志,进行数据分析;

[root@localhost web_application]# pwd
/docker_image/apps/web_application
[root@localhost web_application]# ls
django_app Dockerfile requirements.txt supervisord.conf supervisor.ini
[root@localhost web_application]#

构建web app镜像所需要的文件

APP项目---自己写

ADD django_app/ /root/django_app/
ADD requirements.txt /root/django_app/ ADD supervisord.conf /etc/supervisord.conf
ADD supervisor.ini /etc/supervisord.d/
RUN /zhanggen/python3.6.1/bin/pip3 install -r /root/django_app/requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com EXPOSE 22 8008 CMD ["/usr/bin/supervisord","-c","/etc/supervisord.conf"]

Dockerfile

Django==1.11.4

requirements.txt APP项目需要的 python包

nodaemon=true               ; (start in foreground if true;default false)

supervisord的配置文件 supervisord.conf

配置supervisor需要启动的启动的 程序

ps:一定记得让supervisord进程 在前台运行(修改配置中件  nodaemon=true)

[program:django_project]
command=/zhanggen/python3.6.1/bin/python3 /root/django_app/manage.py runserver 0.0.0.0:8008
process_name=%(program_name)s
autostart=true
user=root
stdout_logfile=/tmp/app.log
stderr_logfile=/tmp/app.error [program:sshd]
command=/usr/sbin/sshd -D
process_name=%(program_name)s
autostart=true
user=root
stdout_logfile=/tmp/sshd.log
stderr_logfile=/tmp/sshd.error

supervisor.ini

构建 web app镜像

Successfully built 73fbd9076308
Successfully tagged zhanggen/django_app:v1
[root@localhost web_application]# pwd
/docker_image/apps/web_application
[root@localhost web_application]# docker build -t zhanggen/django_app:v1 .

docker build -t zhanggen/django_app:v1 .

启动web app

[root@localhost web_application]# docker run --name my_django_app -d -p : -p : zhanggen/django_app:v1
185c311d6a951e33fa01d64a332127cf9ad6d45b0ee60d018ab25be68c0a86bf
[root@localhost web_application]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
185c311d6a95 zhanggen/django_app:v1 "/usr/bin/supervisor…" seconds ago Up seconds 0.0.0.0:->/tcp, 0.0.0.0:->/tcp my_django_app
[root@localhost web_application]#

docker run --name my_django_app -d -p 8008:8008 -p 8022:22 zhanggen/django_app:v1

最后的最后

[root@localhost web_application]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zhanggen/django_app v1 a25dd5479dd9 minutes ago 905MB
zhanggen/python3.6.1 v1 20e32f2fde08 hours ago 882MB
zhanggen/centos v1 9c10a3b17a66 hours ago 300MB
[root@localhost web_application]# docker run --name my_django_app -d -p : -p : zhanggen/django_app:v1

最终构建的3个镜像

六、Docker仓库(Docker Registry)

docker镜像做好了,这些镜像怎么分享给其他同事,其他同事的镜像 How to share with me?

于是私有Docker Hub-----Harbor闪亮登场了!

我们可以把这些镜像 push  / pull 到Docker仓库里面,通过Docker仓库 使镜像 得以分享、传播;

Docker 容器技术

 1.Harbor私有仓库搭建

2.Docker 添加--insecure-registry信任关系

ExecStart=/usr/bin/dockerd --insecure-registry=192.168.226.159:

vim /usr/lib/systemd/system/docker.service

3.首次使用Harbor需要先登录做一下认证 (Authenticating)

[root@localhost /]# docker login 192.168.226.159:
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded

docker login 192.168.226.159:80

4.在提交到Harbor之前 要先对本地镜像进行 docker tag

[root@localhost /]# docker tag 192.168.226.159/zhanggen/django_app:v1 192.168.226.159:80/zhanggen/django_app:v1
[root@localhost /]# docker push 192.168.226.159:80/zhanggen/django_app:v1
The push refers to repository [192.168.226.159:80/zhanggen/django_app]
1adfc5932576: Pushed
f35015fe99dc: Pushed
130d88c10146: Pushed
af1537967ae6: Pushed
8bc7239a5750: Pushed
4044728999b8: Pushed
7393a01b80a0: Pushed
8682a21900da: Pushed
4b12cdc82a32: Pushed
325cddbb1805: Pushed
5e3f3498e333: Pushed
9b0549f1a2e2: Pushed
5d14ce4c4502: Pushed
d7180aa9852e: Pushed
d69483a6face: Mounted from zhanggen/mycentos
v1: digest: sha256:9b4aaeb6d37466a92d3705b68b20c5bf27db1a21ef75456dd2433822b0bf5b60 size: 3457

docker tag 192.168.226.159/zhanggen/django_app:v1 192.168.226.159:80/zhanggen/django_app:v1

 5.docker push ---->Harbor仓库

[root@localhost harbor]# docker login http://192.168.226.159:80
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded
[root@localhost harbor]# docker push 192.168.226.159:80/zhanggen/mycentos:v1
The push refers to repository [192.168.226.159:80/zhanggen/mycentos]
d69483a6face: Pushed
v1: digest: sha256:ca58fe458b8d94bc6e3072f1cfbd334855858e05e1fd633aa07cf7f82b048e66 size: 529
[root@localhost harbor]#

docker push 192.168.226.159:80/zhanggen/mycentos:v1

6.docker pull  本地 <--------Harbor仓库

[root@localhost /]# docker rmi 192.168.226.159:/zhanggen/mycentos:v1
Untagged: 192.168.226.159:/zhanggen/mycentos:v1
Untagged: 192.168.226.159:/zhanggen/mycentos@sha256:ca58fe458b8d94bc6e3072f1cfbd334855858e05e1fd633aa07cf7f82b048e66
[root@localhost /]# docker pull 192.168.226.159:/zhanggen/mycentos:v1
v1: Pulling from zhanggen/mycentos
Digest: sha256:ca58fe458b8d94bc6e3072f1cfbd334855858e05e1fd633aa07cf7f82b048e66
Status: Downloaded newer image for 192.168.226.159:/zhanggen/mycentos:v1
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.226.159/zhanggen/django_app v1 a25dd5479dd9 hours ago 905MB
192.168.226.159:/zhanggen/django_app v1 a25dd5479dd9 hours ago 905MB
zhanggen/django_app v1 a25dd5479dd9 hours ago 905MB
zhanggen/python3.6.1 v1 20e32f2fde08 days ago 882MB
zhanggen/centos v1 9c10a3b17a66 days ago 300MB
192.168.226.159/zhanggen/mycentos v1 9f38484d220f days ago 202MB
192.168.226.159:/zhanggen/mycentos v1 9f38484d220f days ago 202MB
centos latest 9f38484d220f days ago 202MB
goharbor/chartmuseum-photon v0.8.1-v1.7.4 7e2272c02339 weeks ago 113MB
goharbor/harbor-migrator v1.7.4 968c31d07d2f weeks ago 678MB
goharbor/redis-photon v1.7.4 611d1ead0a28 weeks ago .7MB
goharbor/clair-photon v2.0.7-v1.7.4 01090529ab14 weeks ago 165MB
goharbor/notary-server-photon v0.6.1-v1.7.4 737518b1b943 weeks ago 135MB
goharbor/notary-signer-photon v0.6.1-v1.7.4 495dc3326120 weeks ago 132MB
goharbor/harbor-registryctl v1.7.4 723aed7bbf8d weeks ago 102MB
goharbor/registry-photon v2.6.2-v1.7.4 f4743bd7b0d9 weeks ago .7MB
goharbor/nginx-photon v1.7.4 dda34e6afafe weeks ago .9MB
goharbor/harbor-log v1.7.4 bf4916eef530 weeks ago .4MB
goharbor/harbor-jobservice v1.7.4 1b6a0445ae9c weeks ago .1MB
goharbor/harbor-core v1.7.4 e603b8750d26 weeks ago .6MB
goharbor/harbor-portal v1.7.4 2ca1d845cafa weeks ago .6MB
goharbor/harbor-adminserver v1.7.4 5706c65d65dc weeks ago .3MB
goharbor/harbor-db v1.7.4 08d163f732f3 weeks ago 136MB
[root@localhost /]#

docker pull 192.168.226.159:80/zhanggen/mycentos:v1

7.Harbor的 后台管理页面

默认登录密码:Harbor12345

Docker 容器技术

Docker 容器技术

七.docker实践总结

虽然结果只是build了3个镜像,但是我发现docker 的优势在于它可以通过镜像的方式 把Linux系统、开发环境、代码 进行了分层, 我们可以把这些镜像 想象成一个个的积木,有了这些小积木,我们就可以在 实体机、甚至虚拟机里面  灵活、搭建出 各式各样的房子,分给不同需求的人,而且构建速度 快,构建的房子还可以轻易的搬到其他地方;

docker是1种可以 灵活、快速得 构建出 多种不同得 开发、测试 环境的容器技术,Buddy.... 如果你的公司需要构建大量、不同的系统环境用docker 吧!

如果你的代码需要在很多地方快速运行起来用docker吧!

Build-----> Ship---->Run