三 docker 镜像命令
基础镜像命令
docker images #列出本地镜像
docker pull ubuntu:13.10
docker search httpd
docker rmi hello-world
docker commit -m="has update" -a="eric" e218edb10161 runoob/ubuntu:v2
docker tag 860c279d2fec runoob/centos:dev # 为镜像添加一个新的标签
1、原理图
2、将容器封装成镜像
docker commit -m "描述信息" -a"作者信息" 容器ID/容器名称 ?定义镜像名 称:?定义标签
docker commit -m "httpd+index" -a "eric" cm01 httpd_eric:1.0
3、镜像备份压缩打包
docker save 镜像名称:标签 -o 镜像打包的?件名 (eg: xxx.tar) docker save?件默认保存在当前?录 - ?录可以??指定
docker save httpd_eric:1.0 -o httpd_eric.tar
docker export 1e560fca3906 > ubuntu.tar # 导出容器到本地文件
4、压缩打包文件load成镜像
-i, --input string Read from tar archive file, instead of STDIN
docker load -i ./httpd_eric.tar
5、私有本地公共镜像仓库搭建-Registry
①docker pull registry 下载registry镜像
② docker run -dit -p 1000:5000 -v /root/eric-registry:/var/lib/registry registry:latest 创建registry容器
docker exec -it 3c238746e095 /bin/ash
③curl http://127.0.0.1:1000/v2/_catalog 查看本地私有镜像仓库的镜像
④docker tag httpd-eric:1.0 127.0.0.1:1000/root/httpd-eric:1.1 创建容器tag
⑤docker push 127.0.0.1:1000/root/httpd-eric:1.1 推送镜像到本地私有镜像仓库
⑥docker pull 127.0.0.1:1000/root/httpd-eric:1.1 拉取本地私有镜像
docker pull 192.168.8.153:1000/lisi/httpd_shi_01:1.0
6、从零开始来创建一个新的镜像
runoob@runoob:~$ cat Dockerfile
FROM centos:6.7
MAINTAINER Fisher "fisher@sudops.com"
RUN /bin/echo 'root:123456' |chpasswd
RUN useradd runoob
RUN /bin/echo 'runoob:123456' |chpasswd
RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" >/etc/default/local
EXPOSE 22
EXPOSE 80
CMD /usr/sbin/sshd -D
runoob@runoob:~$ docker build -t runoob/centos:6.7 .
Sending build context to Docker daemon 17.92 kB
Step 1 : FROM centos:6.7
---> d95b5ca17cc3
Step 2 : MAINTAINER Fisher "fisher@sudops.com"
---> Using cache
---> 0c92299c6f03
Step 3 : RUN /bin/echo 'root:123456' |chpasswd
---> Using cache
---> 0397ce2fbd0a
Step 4 : RUN useradd runoob
......
-t :指定要创建的目标镜像名
. :Dockerfile 文件所在目录,可以指定Dockerfile 的绝对路径
(以下这部分还需要补充修改)
#其他主机向仓库内容推送镜像 - tag
[root@container-01 ~]# docker tag httpd_zhangsan:1.0
192.168.8.153:1000/lisi/httpd_shi_01:1.0
#报错 - https error 解决?法(1)搭建HTTPS仓库 | 解决?法(2): HTTP?式推送
[root@container-01 ~]# docker push 192.168.8.153:1000/lisi/httpd_shi_01:1.0
The push refers to repository [192.168.8.153:1000/lisi/httpd_shi_01]
Get "https://192.168.8.153:1000/v2/": http: server gave HTTP response to HTTPS client
# docker info
Insecure Registries: 未启?https仓库 - 默认使?http
127.0.0.0/8
# 更改 /etc/docker/daemon.json
{
"registry-mirrors": ["https://lorq21c4.mirror.aliyuncs.com"],
"insecure-registries" : ["192.168.8.153:1000"]
}
~
[root@container-01 ~]# systemctl daemon-reload && systemctl restart docker.service
docker info
Insecure Registries:
192.168.8.153:1000
127.0.0.0/8
# 重新推送
[root@container-01 ~]# docker push 192.168.8.153:1000/lisi/httpd_shi_01:1.0
[root@container-01 ~]# curl 192.168.8.153:1000/v2/_catalog
{"repositories":["lisi/httpd_shi_01","zhangsan/httpd_shi_02"]}