DockerFile文件编写(一)

发布于 2019-10-26  148 次阅读


使用 git 相关命令将附件中提供的 test.php 文件上传到 gogs 的 xiandian 仓库中;在 Client 节点/root/xd_web 路径下编写 Dockerfile 文件,满足以下 12 个要求。

(1)使用第 2 小题创建的 centos-7 镜像作为基本镜像,删除镜像的原始 yum 源, 使用当前系统的 yum 源文件作为镜像的 yum 源。
(2)容器安装 mariadb 数据库服务、java 运行环境、unzip 解压工具、httpd web 服 务器、php、php-mysql 和 git。
(3)将提供的 build_table.sh、start.sh 文件添加到系统的/root 路径下。
(4)添加 apache-tomcat.zip 到/root 路径,添加 index.html 为 tomcat 的主页,并创 建/var/log/httpd,/var/www/html 目录。
(5)利用 git 克隆 gogs 仓库内的 test.php 文件并移动到/var/www/html 路径下,完 成后删除原克隆下来的文件夹。
(6)使用 mysql 用户初始化数据库,设置环境变量中 MYSQL_USER 为 xiandian、 MYSQL_PASS 为 000000、MYSQL_ADDR 为 localhost,要求数据库支持 UTF-8,运行 并修改提供的 build_table.sh 和 start.sh 文件,暴露端口 3306。
(7)解压 apache-tomcat.zip 到/root 路径
(8)添加 build_table.sh 执行权限,完成后执行该程序。
(9)添加 start.sh 文件执行权限。
(10)添加/root/apache-tomcat-6/bin 路径内的文件执行权限。
(11)暴露端口 80、3306、8080。
(12)容器运行时要求自动执行 start.sh 脚本文件。

编写完成后按顺序将本题中使用 git 命令上传的具体操作命令、执行结果及编写的 Dockerfile 文件内容以文本形式提交到答题框。

FROM 10.0.6.83: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 java unzip httpd php php-mysql  git
ADD build_table.sh /root/build_table.sh
ADD start.sh /root/start.sh
ADD apache-tomcat.zip  /root/apache-tomcat.zip
RUN mkdir -p /var/log/httpd
RUN mkdir -p /var/www/html
ADD index.html /root/apache-tomcat-6/webapps/ROOT/index.html
RUN git clone http://10.0.6.81:10080/xiandian/xiandian.git
RUN mv xiandian/test.php /var/www/html/test.php RUN rm -rf xiandian
RUN mysql_install_db --user=mysql
ENV LC_ALL en_US.UTF-8
ENV MYSQL_USER xiandian
ENV MYSQL_PASS 000000
ENV MYSQL_ADDR localhost
ENV TERM linux
RUN unzip /root/apache-tomcat.zip -d /root/
RUN chmod +x /root/build_table.sh
RUN /root/build_table.sh
RUN chmod +x /root/start.sh
RUN chmod u+x /root/apache-tomcat-6/bin/*
EXPOSE 80
EXPOSE 3306
EXPOSE 8080
ENTRYPOINT ["/root/start.sh"]
CMD ""
# git clone http://10.0.6.81:10080/xiandian/xiandian.git
Cloning into 'xiandian'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
# git add .
 # git commit -am "add changes"
[master 1cbbae2] add changes
1 file changed, 31 insertions(+)
create mode 100755 test.php
# git push
 warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use:   git config --global push.default matching To squelch this message and adopt the new behavior now, use:   git config --global push.default simple See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) Username for 'http://10.0.6.81:10080': xiandian
Password for 'http://xiandian@10.0.6.81:10080':
Counting objects: 4, done. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 616 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To http://10.0.6.81:10080/xiandian/xiandian.git    8aad82a..1cbbae2  master -> master

我们都要做生活的高手。