1、使用dockerfile制作nginx+php-fpm镜像,实现lnmp。
1.1 制作基础镜像
创建base目录
进入base目录下,编写dockerfile,构建base基础镜像
FROM centos:centos7.8.2003
MAINTAINER yanczhu
RUN yum install wget -y
&& rm -rf /etc/yum.repos.d/*.repo
&& wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
&& wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel ntpdata crontabs
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
docker images | grep centos 查看构建的centos基础镜像
1.2 制作nginx+php-fpm镜像
进入nginx-php目录下编写dockerfile文件
FROM centos:base
MAINTAINER yanczhu
RUN yum install nginx -y && mkdir -p /data/php
ADD lnmp.conf /etc/nginx/conf.d/
ADD index.php /data/php
ADD abc.html /data/php
RUN yum install php php-mysql php-fpm -y
EXPOSE 80 9000
CMD /usr/sbin/php-fpm -D && nginx -g “daemon off;”
[root@offline nginx-php]# ls
abc.html Dockerfile index.php lnmp.conf nginx.conf
[root@offline nginx-php]# cat abc.html
Hello Docker nginx-php
[root@offline nginx-php]# cat index.php
编写lnmp.conf
Hello Docker nginx-php
编写lnmp.conf
server {
listen 80;
server_name 10.0.1.24;
root /data/php;
index index.html index.php;
location ~* .php$ {
root /data/php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
d
o
c
u
m
e
n
t
r
o
o
t
document_root
documentrootfastcgi_script_name;
include fastcgi_params;
}
}
1.4 启动nginx-php容器
1.5 测试
2、使用dockerfile制作tomcat镜像,并实现对jsp测试页访问
2.1 编写Dockerfile文件
#Tomcat Base Image
FROM centos:centos7.8.2003
MAINTAINER yanczhu “33178387@qq.com”
ADD apache-tomcat-8.5.57.tar.gz /usr/local/src/
RUN ln -sv /usr/local/src/apache-tomcat-8.5.57 /usr/local/src/tomcat
RUN yum install java-1.8.0-openjdk -y
ADD index.jsp /usr/local/src/tomcat/webapps/ROOT/
EXPOSE 8080 8009
ADD run_tomcat.sh /
CMD [“/run_tomcat.sh”]
2.2 准备所需文件
vim run_tomcat.sh
#!/bin/bash
sh /usr/local/src/tomcat/bin/startup.sh start
tail -f /etc/hosts
vim index.jsp
<%@ page language=“java” %>
<%@ page import=“java.util.*” %>