IDEA deploys Docker in the form of war package (Dockerfile file)

IDEA deploys Docker in the form of war package-Dockerfile

1. Environmental preparation

Prerequisite preparation:
https://blog.csdn.net/YKenan/article/details/111446036 The
war package depends on tomcat

# 镜像名称
FROM centos8_1.8
# 作者
MAINTAINER ykenan
# 运行命令
RUN mkdir /home/tomcat/
# 复制
COPY apache-tomcat-9.0.12.tar.gz /home/tomcat/
# 切换工作路径
WORKDIR /home/tomcat/
# 解压
RUN tar -zxvf apache-tomcat-9.0.12.tar.gz
# 删除
RUN rm apache-tomcat-9.0.12.tar.gz
# 定义变量
ENV DIR_TOMCAT /home/tomcat/apache-tomcat-9.0.12/
# 删除文件夹
RUN rm -rf $DIR_TOMCAT/webapps/*
# 切换工作路径
WORKDIR $DIR_TOMCAT
# 暴露端口
EXPOSE 8080
# 启动 tomcat
CMD ["./bin/catalina.sh", "run"]

Run the above Dockerfile

docker build -t tomcat_1.8 .

2. Configure Docker in IDEA

Insert picture description here
Insert picture description here

Dockerfile file content

# 基于 tomcat
FROM tomcat_1.8
# 作者
MAINTAINER ykenan
# 定义变量
ENV DIR_WEBAPP /home/tomcat/apache-tomcat-9.0.12/webapps/
# 切换工作路径
WORKDIR $DIR_WEBAPP
# 添加本地的 war 包到远程容器中
ADD ./target/ykenan-1.0.war ykenan.war
# 安装 unzip
RUN yum install -y unzip zip
# 解压 war 包到 ROOT 目录
RUN unzip ykenan.war -d ykenan
# 暴露接口
EXPOSE 8080
# 启动 Tomcat
CMD ["../bin/catalina.sh","run"]

Just run it. This method is relatively simple, and jar can also be like this. No private warehouse is used.

If the mirror has none, it means that the Dockerfile is wrong.

3. Dockerfile in Jar package

# 基础镜像使用java
FROM centos
# 作者
MAINTAINER YKenan
# 安装 JDK
RUN yum install -y java-1.8.0-openjdk-devel.x86_64
# 将 jar 包添加到容器中并更名为 app.jar
ADD ./target/ykenan-1.0.jar ykenan.jar
# 运行jar包
# touch 命令, 如果没有文件创建则创建文件, 如果文件已存在, 则修改时间戳
RUN bash -c 'touch /ykenan.jar'
ENTRYPOINT ["java","-jar","/ykenan.jar"]

Guess you like

Origin blog.csdn.net/YKenan/article/details/111462629