zoukankan      html  css  js  c++  java
  • Docker: 构建Nginx,PHP,Tomcat基础镜像

    Usage: docker build [OPTIONS] PATH | URL | - [flags]

    Options: -t,

    --tag list # 镜像名称 -f,

    --file string # 指定Dockerfile文件位置

    前提:已经准备好了 如下文件(谁需要相关文件的,最下面有我微信,欢迎添加获取):

    #现把文件从windows上传输到linux,发现xshell没有安装 rz命令,那么就不支持把windows文件拖进linux机器
    [root@192 ~]# rz
    -bash: rz: 未找到命令
    #安装rz工具
    [root@192 yum install lrzsz
    已加载插件:fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: ftp.sjtu.edu.cn
     * updates: ftp.sjtu.edu.cn
    base                                                                                      | 3.6 kB  00:00:00     
    docker-ce-stable                                                                          | 3.5 kB  00:00:00     
    extras                                                                                    | 3.4 kB  00:00:00     
    updates                                                                                   | 3.4 kB  00:00:00     
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 lrzsz.x86_64.0.0.12.20-36.el7 将被 安装
    --> 解决依赖关系完成
    
    依赖关系解决
    
    =================================================================================================================
     Package                 架构                     版本                              源                      大小
    =================================================================================================================
    正在安装:
     lrzsz                   x86_64                   0.12.20-36.el7                    base                    78 k
    
    事务概要
    =================================================================================================================
    安装  1 软件包
    
    总下载量:78 k
    安装大小:181 k
    Is this ok [y/d/N]: y
    Downloading packages:
    lrzsz-0.12.20-36.el7.x86_64.rpm                                                           |  78 kB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      正在安装    : lrzsz-0.12.20-36.el7.x86_64                                                                  1/1 
      验证中      : lrzsz-0.12.20-36.el7.x86_64                                                                  1/1 
    
    已安装:
      lrzsz.x86_64 0:0.12.20-36.el7                                                                                  
    
    完毕!
    #将windows文件拖进xshell, 会出现图形界面,显示传输进度
    [root@192 ~]# rz -E
    rz waiting to receive.
    #确认 dockerfile_.zip传输进了linux宿主机
    [root@192 ~]# ls
    anaconda-ks.cfg  dockerfile_.zip  nginx.tar
    # 发现unzip工具没有安装
    [root@192 ~]# unzip
    -bash: unzip: 未找到命令
    #安装unzip工具
    [root@192 ~]# yum install unzip -y
    已加载插件:fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: ftp.sjtu.edu.cn
     * updates: ftp.sjtu.edu.cn
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 unzip.x86_64.0.6.0-19.el7 将被 安装
    --> 解决依赖关系完成
    
    依赖关系解决
    
    =================================================================================================================
     Package                  架构                      版本                           源                       大小
    =================================================================================================================
    正在安装:
     unzip                    x86_64                    6.0-19.el7                     base                    170 k
    
    事务概要
    =================================================================================================================
    安装  1 软件包
    
    总下载量:170 k
    安装大小:365 k
    Downloading packages:
    unzip-6.0-19.el7.x86_64.rpm                                                               | 170 kB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      正在安装    : unzip-6.0-19.el7.x86_64                                                                      1/1 
      验证中      : unzip-6.0-19.el7.x86_64                                                                      1/1 
    
    已安装:
      unzip.x86_64 0:6.0-19.el7                                                                                      
    
    完毕!
    解压 dockerfile_.zip 文件
    [root@192 ~]# unzip dockerfile_.zip 
    Archive:  dockerfile_.zip
      inflating: Dockerfile-nginx        
      inflating: Dockerfile-php          
      inflating: Dockerfile-tomcat       
      inflating: nginx.conf              
      inflating: php-fpm.conf            
      inflating: php.ini                 
    [root@192 ~]# ls -l
    总用量 110492
    -rw-------. 1 root root      1282 3月  11 16:29 anaconda-ks.cfg
    -rw-r--r--  1 root root       833 11月 25 20:29 Dockerfile-nginx
    -rw-r--r--  1 root root      1331 11月  3 11:06 Dockerfile-php
    -rw-r--r--  1 root root       862 11月 25 20:30 Dockerfile-tomcat
    -rw-r--r--  1 root root     33157 11月 25 20:30 dockerfile_.zip
    -rw-r--r--  1 root root      1137 10月 29 03:02 nginx.conf
    -rw-r--r--. 1 root root 112984576 3月  11 17:37 nginx.tar
    -rw-r--r--  1 root root     23104 10月 29 02:57 php-fpm.conf
    -rw-r--r--  1 root root     73696 11月  3 12:55 php.ini
    [root@192 ~]# vi Dockerfile-nginx 
    [root@192 ~]# docker build -t nginx:v1 -f Dockerfile-nginx .
    Sending build context to Docker daemon  113.1MB
    Step 1/9 : FROM centos:7
     ---> 1e1148e4cc2c
    Step 2/9 : MAINTAINER www.ctnrs.com
     ---> Running in bf77ab5a1997
    Removing intermediate container bf77ab5a1997
     ---> 518178772205
    Step 3/9 : RUN yum install -y gcc gcc-c++ make     openssl-devel pcre-devel gd-devel     iproute net-tools telnet wget curl &&     yum clean all &&     rm -rf /var/cache/yum/*
     
    ......
    Step 8/9 : EXPOSE 80 ---> Running in 53d27a40eef7 Removing intermediate container 53d27a40eef7 ---> 39fe3e3e4c0c Step 9/9 : CMD ["nginx", "-g", "daemon off;"] ---> Running in 17796c30c838 Removing intermediate container 17796c30c838 ---> a5412fe37cac Successfully built a5412fe37cac Successfully tagged nginx:v1 [root@192 ~]# 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. #确认nginx v1镜像构建成功 [root@192 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx v1 a5412fe37cac About a minute ago 361MB nginx latest 881bd08c0b08 9 days ago 109MB busybox latest d8233ab899d4 3 weeks ago 1.2MB centos 7 1e1148e4cc2c 3 months ago 202MB centos latest 1e1148e4cc2c 3 months ago 202MB java 8 d23bdf5b1b1b 2 years ago 643MB #构建php镜像,构建比较慢,大约持续 7~8分钟 [root@192 ~]# docker build -t php:v1 -f Dockerfile-php . ...... Successfully built d48e00d7de94 Successfully tagged php:v1 #确认php v1 构建成功  [root@192 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE php v1 d48e00d7de94 34 seconds ago 514MB nginx v1 a5412fe37cac 16 minutes ago 361MB nginx latest 881bd08c0b08 9 days ago 109MB busybox latest d8233ab899d4 3 weeks ago 1.2MB centos 7 1e1148e4cc2c 3 months ago 202MB centos latest 1e1148e4cc2c 3 months ago 202MB java 8 d23bdf5b1b1b 2 years ago 643MB [root@192 ~]# ls anaconda-ks.cfg Dockerfile-php dockerfile_.zip nginx nginx.tar php php-fpm.conf php.ini tomcat [root@192 ~]# cd tomcat/ [root@192 tomcat]# ls Dockerfile-tomcat #构建tomcat前,先到 http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/ 查看版本,修改VERSION=为你需要的版本 [root@192 tomcat]# vi Dockerfile-tomcat [root@192 tomcat]# docker build -t tomcat:v1 -f Dockerfile-tomcat . Sending build context to Docker daemon 2.56kB Step 1/9 : FROM centos:7 ---> 1e1148e4cc2c .... Successfully built 5f8fe4ca82ba Successfully tagged tomcat:v1 #现在已经构建好了 tomcat, php,nginx 标签都是v1的镜像 [root@192 tomcat]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat v1 5f8fe4ca82ba 2 minutes ago 427MB php v1 d48e00d7de94 16 minutes ago 514MB nginx v1 a5412fe37cac 32 minutes ago 361MB nginx latest 881bd08c0b08 9 days ago 109MB busybox latest d8233ab899d4 3 weeks ago 1.2MB centos 7 1e1148e4cc2c 3 months ago 202MB centos latest 1e1148e4cc2c 3 months ago 202MB java 8 d23bdf5b1b1b 2 years ago 643MB

    作者: 梅梅~

    出处: https://www.cnblogs.com/keeptesting

    关于作者:专注软件测试,测试运维相关工作,请多多赐教!

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出, 原文链接 欢迎沟通交流加微信联系。 微信:yangguangkg20140901 暗号:博客园.

  • 相关阅读:
    记一次阿里云硬盘在线扩容
    大文件传输技巧-----split切割
    数据库迁移-------通过ibdata1文件和数据库文件迁移
    小技巧---------------vim 使用技巧 set paste 解决粘贴乱序问题
    webfrom 做项目的注意事项
    webform 复合控件
    wenfrom的简单控件和repeater控件
    分页功能 与 分类查询功能合并
    内置对象2
    简单的人员管理系统
  • 原文地址:https://www.cnblogs.com/keeptesting/p/10537039.html
Copyright © 2011-2022 走看看