2019/3/7 应用构建
1.Nginx Web
编写以上题构建的centos-7镜像为基础镜像,构建Nginx服务,Dockerfile要求删除镜像的yum源,使用当前系统的yum源文件,完成后安装nginx服务,修改提供的nginx.conf文件将转发url修改为Rancher平台访问的URL,完成后将提供的nginx.conf文件替换系统安装nginx.conf文件,此镜像要求暴露9090端口,容器启动是自动启动nginx服务,完成后启动创建的镜像并查询Dockerfile文件,使用curl命令检查nginx网页运行情况,将以上操作命令及检查结果填入命令行界面。
# cat Dockerfile
FROM 192.168.200.12:5000/centos-7
MAINTAINER Xiandian
RUN rm -fv /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
RUN yum install -y nginx
RUN rm -fv /etc/nginx/nginx.conf
ADD nginx.conf /etc/nginx/
EXPOSE 9090
ENTRYPOINT /usr/sbin/nginx
# docker build -t 192.168.200.12:5000/taicai/nginx:v1.0 .
# docker run -it -d -P 192.168.200.12:5000/taicai/nginx:v1.0
# curl 192.168.200.12:32778
{"type":"collection","resourceType":"apiVersion","links":{"self":"http://192.168.200.10/","latest":"http://192.168.200.10/v1"},"createTypes":{},"actions":{},"data":[{"id":"v1","type":"apiVersion","links":{"self":"http://192.168.200.10/v1"},"actions":{}}],"sortLinks":{},"pagination":null,"sort":null,"filters":{},"createDefaults":{}}
2.数据库
编写以上题构建的centos-7镜像为基础镜像,构建数据库服务,Dockerfile要求删除镜像的yum源,使用当前系统的yum源文件,完成后安装mariadb服务,使用mysql用户初始化数据库,添加MYSQL_USER、MYSQL_PASS环境变量,要求数据库支持中文,运行并修改提供的build_table.sh和run.sh文件暴露端口3306,容器开机运行mysld_safe命令,完成后启动创建的镜像并查询Dockerfile文件,进入容器查看容器的数据库列表,将以上操作命令及检查结果填入命令行界面。
# cat Dockerfile
FROM 192.168.200.12:5000/centos-7
MAINTAINER Xiandian
RUN rm -fv /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
RUN yum install -y mariadb-server
RUN mysql_install_db --user=mysql
ENV LC_ALL en_US.UTF-8
ENV MYSQL_USER xiandian
ENV MYSQL_PASS xiandian
ADD build_table.sh /root/build_table.sh
RUN chmod +x /root/build_table.sh
RUN /root/build_table.sh
ADD run.sh /root/run.sh
RUN chmod u+x /root/run.sh
EXPOSE 3306
CMD mysqld_safe
# docker build -t 192.168.200.12:5000/taicai/centos-mariadb:v1.0 .
# docker run -dit -P 192.168.200.12:5000/taicai/centos-mysql:v1.0
bash-4.2# mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select * from chinaskills.company;
+----------+-------+
| name | years |
+----------+-------+
| xiandian | 2014 |
| xiandian | 2015 |
+----------+-------+
2 rows in set (0.00 sec)
3.apache+php
编写以上题构建的centos-7镜像为基础镜像,构建apache+php服务,Dockerfile要求删除镜像的yum源,使用当前系统的yum源文件,安装httpd、php和php-mysql服务,创建工作目录为/root/,创建/var/log/httpd,/var/www/html/目录,创建MYSQL_ADDR(地址:端口)、MYSQL_USER(用户名)、MYSQL_PASS环境变量,要求数据库支持中文,将提供的test.php文件添加到httpd运行的根目录,暴露端口80,将提供的run.sh文件添加到/root/目录下,容器开机运行run.sh脚本,完成后启动创建的镜像并查询Dockerfile文件,使用curl命令获取容器httpd服务test.php文件,利用浏览器访问暴露的页面,将以上操作命令及检查结果填入命令行界面。
# cat Dockerfile
FROM 192.168.200.12:5000/centos-7
MAINTAINER Xiandian
RUN rm -fv /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
WORKDIR /root/
RUN yum install -y httpd php php-mysql
RUN mkdir -p /var/log/httpd
RUN mkdir -p /var/www/html
ENV MYSQL_ADDR 172.17.0.5
ENV MYSQL_USER xiandian
ENV MYSQL_PASS xiandian
ENV TERM linux
ENV LC_ALL en_US.UTF-8
ADD test.php /var/www/html/test.php
EXPOSE 80
ADD run.sh /root/run.sh
RUN chmod u+x /root/run.sh
CMD /root/run.sh
# docker build -t 192.168.200.12:5000/taicai/apache_php:v1.0 .
# docker run -itdP 192.168.200.12:5000/taicai/apache_php:v1.0
# curl 192.168.200.12:32796/test.php
<table border='1'>
<tr>
<th>NAME</th>
<th>YEARS</th>
</tr><tr><td>xiandian</td><td>2014</td></tr><tr><td>xiandian</td><td>2015</td></tr></table>
4.Tomcat
编写以上题构建的centos-7镜像为基础镜像,构建Tomcat服务,Dockerfile要求删除镜像的yum源,使用当前系统的yum源文件,安装java和unzip服务,将提供的apache-tomcat.zip文件添加到/root/目录下,露端口8080,将提供的index.html文件添加到tomcat的网页运行的目录下,容器开机运行catalina.sh脚本,完成后启动创建的镜像并查询Dockerfile文件,使用curl命令获取容器的tomcat服务的首页,进入容器查询容器jdk版本和tomcat版本信息,将以上操作命令及检查结果填入命令行界面。
# cat Dockerfile
FROM 192.168.200.12:5000/centos-7
MAINTAINER Xiandian
RUN rm -fv /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
RUN yum install -y java unzip
ENV LC_ALL en_US.UTF-8
ADD apache-tomcat.zip /root/apache-tomcat.zip
RUN unzip /root/apache-tomcat.zip -d /root/
EXPOSE 8080
RUN chmod u+x /root/apache-tomcat-6/bin/*
ADD index.html /root/apache-tomcat-6/webapps/ROOT/index.html
ENV CATALINA_HOME /root/apache-tomcat-6
CMD ${CATALINA_HOME}/bin/catalina.sh run
# docker build -t 192.168.200.12:5000/taicai/java_web:v1.0 .
# docker run -itdP 192.168.200.12:5000/taicai/java_web:v1.0
# curl 192.168.200.12:32799
Xiandian WEB
bash-4.2# java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)
bash-4.2# ./catalina.sh version
Server version: Apache Tomcat/6.0.20
Server built: May 14 2009 01:13:50
Server number: 6.0.20.0
OS Name: Linux
OS Version: 3.10.0-229.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_65-b17
JVM Vendor: Oracle Corporation
********************************************************
FROM 10.0.3.138:5000/centos:latest
MAINTAINER Xiandian
RUN rm -fv /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
ADD yum.tar /opt/
RUN yum clean all
RUN yum install -y java unzip
ENV LC_ALL en_US.UTF-8
ADD apache-tomcat-7.0.56.zip /root/apache-tomcat-7.0.56.zip
RUN unzip /root/apache-tomcat-7.0.56.zip -d /root/
EXPOSE 8081
RUN chmod u+x /root/apache-tomcat-7.0.56/bin/*
ADD jenkins.war /root/apache-tomcat-7.0.56/webapps/ROOT.war
ENV CATALINA_HOME /root/apache-tomcat-7.0.56
CMD ${CATALINA_HOME}/bin/catalina.sh run
[root@server yum]# cat /root/dockerfile/Dockerfile
FROM centos-7
RUN rm -f /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d
RUN yum install java unzip -y
ENV LC_ALL en_US.UTF-8
ADD apache-tomcat-7.0.56.zip /root/apache-tomcat-7.0.56.zip
RUN unzip /root/apache-tomcat-7.0.56.zip -d /root/
EXPOSE 8081
RUN chmod u+x /root/apache-tomcat-7.0.56/bin/*
ADD jenkins.war /root/apache-tomcat-7.0.56/webapps/ROOT.war
ENV CATALINA_HOME /root/apache-tomcat-7.0.56
CMD ${CATALINA_HOME}/bin/catalina.sh run
[root@server yum]#
[root@server dockerfile]# cat Dockerfile
FROM centos-7
RUN rm -f /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d
RUN yum install java unzip -y
ENV LC_ALL en_US.UTF-8
ADD apache-tomcat-7.0.56.zip /root/apache-tomcat-7.0.56.zip
RUN unzip /root/apache-tomcat-7.0.56.zip -d /root/
EXPOSE 8081
RUN chmod u+x /root/apache-tomcat-7.0.56/bin/*
ADD index.html /root/apache-tomcat-7.0.56/webapps/ROOT/index.html
ENV CATALINA_HOME /root/apache-tomcat-7.0.56
CMD /root/apache-tomcat-7.0.56/bin/catalina.sh run
[root@server dockerfile]#
[root@server dockerfile]# cat local.repo
[docker]
name=docker
baseurl=ftp://192.168.140.10/docker/docker
gpgcheck=0
enabled=1
[cenots]
name=centos
baseurl=ftp://192.168.140.10/centos
gpgcheck=0
enabled=1
[yum]
name=yum
baseurl=ftp://192.168.140.10/yum/yum
gpgcheck=0
enabled=1