Docker-容器服务 Container Service04(构建镜像+仓库配置)

Docker-构建镜像-仓库配置 04

Docker-容器服务 Container Service04(构建镜像+仓库配置)

一、Docker 镜像介绍

Docker镜像构建分为两种:
1) 手动构建
2) Dockerfile(自动构建)

二、手动构建过程

基于 centos 镜像进行构建,制作 nginx镜像

1)创建镜像,并安装nginx

[root@localhost opt]# docker run --name qiuyuetao -it centos
#  在centos上装个nginx
#  阿里云找到epel源
[root@0fa09f7a0afe /]# rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
[root@0fa09f7a0afe /]# yum install nginx -y       #安装nginx

Docker-容器服务 Container Service04(构建镜像+仓库配置)

2)修改nginx配置文件,让它运行在前台

[root@0fa09f7a0afe /]# head /etc/nginx/nginx.conf
daemon off;  ## 取消后台运行,在user 上面添加这一行
user nginx;

3) 修改完之后 exit 退出

[root@localhost 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

[root@localhost opt]# docker commit -m "Mynginx" 0fa09f7a0afe qiuyuetao/qiuyuetao:v1

[root@localhost 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镜像

[root@localhost opt]# docker run -d -p 82:80  qiuyuetao/qiuyuetao:v1 nginx
3f78858078c2aa4805dbf255a654cd2c136d3ee6f814527ebb7eb93d4edfb657
##   -d 后台运行
##   -p 指定端口
##   qiuyuetao/qiuyuetao:v1 版本库及版本号
##  nginx 执行的命令,例如/bin/bash ,如果nginx没有环境变量,需要数据全路径

nginx展示页

[root@localhost 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

Docker-容器服务 Container Service04(构建镜像+仓库配置)

猜你喜欢

转载自blog.51cto.com/qiuyt/2160843
今日推荐