Docker: 構建Nginx,PHP,Tomcat基礎鏡像

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

Options: -t,java

--tag list # 鏡像名稱 -f,linux

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

 

前提:已經準備好了 以下文件(誰須要相關文件的,最下面有我微信,歡迎添加獲取):c++

 

#現把文件從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

 

做者: 梅梅~docker

出處: https://www.cnblogs.com/keeptestingshell

關於做者:專一軟件測試,測試運維相關工做,請多多賜教!apache

本文版權歸做者和博客園共有,歡迎轉載,但未經做者贊成必須保留此段聲明,且在文章頁面明顯位置給出, 原文連接 歡迎溝通交流加微信聯繫。 微信:yangguangkg20140901 暗號:博客園.windows

相關文章
相關標籤/搜索