# static_resources **Repository Path**: chenl16/static_resources ## Basic Information - **Project Name**: static_resources - **Description**: by building docker image to generate API - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-06-11 - **Last Updated**: 2024-06-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # static_resources #### 介绍 使用docker 镜像快速构建Linux、Apache2、Mysql、Java、Tomcat多个环境下,使用Servlet上传本地文件至Apache2服务器中,再将上传的服务器文件地址写入Mysql数据库中,最后得到JSON格式的数据。 ``` ├── 50-server.cnf ##Mysql配置文件,用于开启远程登录 ├── apache-tomcat-8.5.100.tar.gz ##Tomcat安装包 ├── Dockerfile ##Dockerfile文件 ├── file_api_war.war ##java项目打包文件 └── init.sh ##Mysql初始化文件 ``` ``` ##Dockerfile文件 #指定基础镜像为Ubuntu 22.04 FROM ubuntu:22.04 LABEL maintainer=chenlin #将当前目录下的init.sh文件复制到镜像的/opt/目录下 ENV DEBIAN_FRONTEND=noninteractive COPY ./init.sh /opt/ # 安装MYSQL RUN apt-get update && \ apt-get install wget software-properties-common dirmngr ca-certificates apt-transport-https -y && \ apt-get install -y mariadb-server mariadb-client&& \ bash /opt/init.sh COPY ./50-server.cnf /etc/mysql/mariadb.conf.d/50-server.cnf # 安装Java RUN apt-get install -y openjdk-11-jdk && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64 # 安装Tomcat ADD ./apache-tomcat-8.5.100.tar.gz /root/ ENV CATALINA_HOME /root/apache-tomcat-8.5.100 COPY ./file_api_war.war /root/apache-tomcat-8.5.100/webapps/ # 安装Apache2 RUN apt update && \ apt-get install -y apache2 locales && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* && \ mkdir /var/www/html/images && \ chmod -R 755 /var/www/html/* RUN sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen ENV LANG en_US.UTF-8 ENV LANG en_US.UTF-8 ENV LANG en_US.UTF-8 EXPOSE 80 8080 3306 CMD service apache2 start && ./root/apache-tomcat-8.5.100/bin/startup.sh run && mysqld_safe --user=root ##init.sh脚本文件 #!/bin/bash mysql_install_db --user=root sleep 3 mysqld_safe --user=root & sleep 5 mysqladmin -u root password "000000" # 授权 mysql -u root -p000000 -e "use mysql; grant all privileges on *.* to 'root'@'%' identified by '000000' with grant option;" mysql -u root -p000000 -e "use mysql; grant all privileges on *.* to 'root'@'localhost' identified by '000000' with grant option;" # 刷新权限 mysql -u root -p000000 -e "flush privileges;" mysql -u root -p000000 -e "create database static_resources character set utf8mb4 collate utf8mb4_general_ci;use static_resources;create table file_db( id int(4) not null auto_increment,name char(20) not null, file_url varchar(255),primary key (id));" ##构建方法 docker build -t static_api:v1.0 . ```