Docker-容器服务 Container Service04(构建镜像+仓库配置)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker-容器服务 Container Service04(构建镜像+仓库配置)相关的知识,希望对你有一定的参考价值。
Docker-构建镜像-仓库配置 04
一、Docker 镜像介绍
Docker镜像构建分为两种:
1) 手动构建
2) Dockerfile(自动构建)
二、手动构建过程
基于 centos 镜像进行构建,制作 nginx镜像
1)创建镜像,并安装nginx
[[email protected] opt]# docker run --name qiuyuetao -it centos
# 在centos上装个nginx
# 阿里云找到epel源
[[email protected] /]# rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
[[email protected] /]# yum install nginx -y #安装nginx
2)修改nginx配置文件,让它运行在前台
[[email protected] /]# head /etc/nginx/nginx.conf
daemon off; ## 取消后台运行,在user 上面添加这一行
user nginx;
#修改完之后 exit 退出
3) 查询Container ID
[[email protected] opt]# docker ps -a #找到刚才创建容器的CONTAINER ID
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0fa09f7a0afe centos "/bin/bash" 20 minutes ago Up 4 minutes qiuyuetao
4)将现有容器保存为镜像,命名为qiuyuetao/qiuyuetao
[[email protected] opt]# docker commit -m "Mynginx" 0fa09f7a0afe qiuyuetao/qiuyuetao:v1
[[email protected] opt]# docker images #查看镜像是否生成
REPOSITORY TAG IMAGE ID CREATED SIZE
qiuyuetao/qiuyuetao v1 14ea0f79983d 24 seconds ago 406 MB
#注释
#-m 描述
#容器ID
第一个qiuyuetaor是仓库的名称
第二个qiuyuetao是镜像的名称
#v1 标签,如果是最后一个版本我们可以打latest
5) 使用刚制作好的nginx镜像
[[email protected] opt]# docker run -d -p 82:80 qiuyuetao/qiuyuetao:v1 nginx
3f78858078c2aa4805dbf255a654cd2c136d3ee6f814527ebb7eb93d4edfb657
## -d 后台运行
## -p 指定端口
## qiuyuetao/qiuyuetao:v1 版本库及版本号
## nginx 执行的命令,例如/bin/bash ,如果nginx没有环境变量,需要数据全路径
6)nginx展示页
[[email protected] opt]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f78858078c2 qiuyuetao/qiuyuetao:v1 "nginx" 4 minutes ago Up 4 minutes 0.0.0.0:82->80/tcp wizardly_lumiere
7)日志查询
[[email protected] opt]# docker exec -it 3f78858078c2 tail /var/log/nginx/access.log
192.168.56.1 - - [16/Aug/2018:17:27:25 +0000] "GET / HTTP/1.1" 200 3700 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"
192.168.56.1 - - [16/Aug/2018:17:27:25 +0000] "GET /robots.txt HTTP/1.1" 404 3650 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"
192.168.56.1 - - [16/Aug/2018:17:27:25 +0000] "GET /nginx-logo.png HTTP/1.1" 200 368 "http://192.168.56.11:82/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"
192.168.56.1 - - [16/Aug/2018:17:27:25 +0000] "GET /poweredby.png HTTP/1.1" 200 2811 "http://192.168.56.11:82/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"
192.168.56.1 - - [16/Aug/2018:17:27:26 +0000] "GET /favicon.ico HTTP/1.1" 404 3650 "http://192.168.56.11:82/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"
8)手动构建总结:
以上是关于Docker-容器服务 Container Service04(构建镜像+仓库配置)的主要内容,如果未能解决你的问题,请参考以下文章
容器,Docker和Azure Container Service