Skip to content

Commit

Permalink
修改dockerFile编译方法
Browse files Browse the repository at this point in the history
  • Loading branch information
SQ committed Nov 10, 2023
1 parent f6e0202 commit de537ad
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 11 deletions.
68 changes: 68 additions & 0 deletions CentOS-Base.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
35 changes: 25 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ FROM maven:3.9.4-eclipse-temurin-17-alpine AS builder
MAINTAINER SQ

WORKDIR /build/
# 时区与字符设置UTF-8并配置环境
ENV TZ=Asia/Shanghai
ENV LANG=C.UTF-8
ENV apiPort="8099"
ENV webPort="80"
ENV TimeZone=Asia/Shanghai


#复制源码信息
COPY pom.xml /build/
Expand All @@ -23,17 +18,37 @@ RUN mvn clean package
#运行镜像
FROM centos:7

# 时区与字符设置UTF-8并配置环境
ENV TZ=Asia/Shanghai
ENV LANG=C.UTF-8
ENV apiPort="8099"
ENV webPort="80"
ENV TimeZone=Asia/Shanghai


RUN yum update \
&& yum install -y java-17-openjdk nginx
#
#RUN yum makecache
RUN yum update -y wget

COPY --from=builder /build/target/MusicServer2.0.jar /app/app.jar
RUN rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
RUN yum install -y nginx

RUN yum install -y wget
RUN wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
RUN yum install -y ./jdk-17_linux-x64_bin.rpm

#RUN wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm
#RUN yum install -y ./nginx-1.18.0-1.el7.ngx.x86_64.rpm



COPY --from=builder /build/target/MusicServer2.0.jar /app/app.jar
RUN mkdir -p /usr/local/nginx/conf/
RUN echo "worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen ${webPort}; server_name localhost; location / { root html; index index.html index.htm; } location /sqmusic-api/ { proxy_pass http://localhost:${apiPort}/; proxy_http_version 1.1; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}" > /usr/local/nginx/conf/nginx.conf


#将启动脚本拷贝到容器里面的/usr/local/project下面
COPY run.sh /usr/local/project
COPY docker-run.sh /usr/local/project/docker-run.sh
#给run.sh可执行权限
RUN chmod 777 /usr/local/project/docker-run.sh

Expand Down
2 changes: 1 addition & 1 deletion docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ echo "java-端口:$0";
echo "web-端口:$1";

# 启动nginx服务
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx -c /usr/local/nginx/conf/nginx.conf

#启动后端jar包,日志打印不额外存储
nohup java -Dserver.port=$0 -jar /app/app.jar >/dev/null 2>& 1 &
Expand Down

0 comments on commit de537ad

Please sign in to comment.