DockerFile创建镜像 运行jar包

1. 新建DockerFile,写入内容

        

vi DockerFile
# 指定基础镜像,用于后续的指令构建。
FROM openjdk:17-jdk-alpine
# 在容器内部设置环境变量。
ENV MYPATH /root/ta
# 设置后续指令的工作目录。
WORKDIR $MYPATH

#将文件、目录或远程URL复制到镜像中。
ADD ta-0.0.1-SNAPSHOT.jar ta-0.0.1-SNAPSHOT.jar

#暴露端口
EXPOSE 8080
# 运行jar包
CMD java -jar ta-0.0.1-SNAPSHOT.jar
#定义系统环境变量
ENV username=ta
ENV password=123456

2. DockerFile创建镜像(当前目录保证只有DockerFile 和 jar包)

        

docker build -f DockerFile  -t  ta:1.0.0  .

  3. 运行容器

docker run -d  --net host   --name  ta ta:1.0.0

查看容器日志

[root@ETL027207 tmp]# docker logs -f --tail 200 ta
Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.0)

2023-12-27T07:58:45.248Z  INFO 1 --- [           main] com.ta.TaApplication                     : Starting TaApplication v0.0.1-SNAPSHOT using Java 17-ea with PID 1 (/root/ta/ta-0.0.1-SNAPSHOT.jar started by root in /root/ta)
2023-12-27T07:58:45.265Z  INFO 1 --- [           main] com.ta.TaApplication                     : No active profile set, falling back to 1 default profile: "default"
2023-12-27T07:58:48.641Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2023-12-27T07:58:48.656Z  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-12-27T07:58:48.657Z  INFO 1 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.16]
2023-12-27T07:58:48.922Z  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-12-27T07:58:48.936Z  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3398 ms
Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
2023-12-27T07:58:51.107Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path ''
2023-12-27T07:58:51.125Z  INFO 1 --- [           main] com.ta.TaApplication                     : Started TaApplication in 6.838 seconds (process running for 7.659)
2023-12-27T07:59:41.424Z  INFO 1 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-12-27T07:59:41.424Z  INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2023-12-27T07:59:41.426Z  INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 2 ms
^C

ok 运行成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值