springboot-dokcer
项目就一个java文件,仅用于样例
package com.example.demo; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @SpringBootApplication
@RestController
public class BootDockerApplication
{ @Value("${app.env}")
private String env; @RequestMapping("/")
public String home()
{
return "Hello Docker World-this env "+env;
} public static void main(String[] args)
{
SpringApplication.run(BootDockerApplication.class, args);
} }
Dockerfile
FROM openjdk:-jdk-alpine
VOLUME /tmp
#编译传入的参数
ARG JAR_FILE
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["sh","-c","java $JAVA_OPTS -jar /app.jar"]
关于sh -c
执行sh -c ls 和 sh ls
-c string If the -c option is present, then commands are read from
string. If there are arguments after the string, they are
assigned to the positional parameters, starting with $.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion> <groupId>com.caicai</groupId>
<artifactId>boot-demo</artifactId>
<version>1.0</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5..RELEASE</version>
</parent> <properties>
<java.version>1.8</java.version>
<!-- 可修改成自己的docker仓库名 -->
<docker.image.prefix>zzzzz</docker.image.prefix>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build> <plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
<!-- auto push -->
<!--
<executions>
<execution>
<id>default</id>
<phase>install</phase>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
-->
</plugin>
</plugins>
</build> </project>
springboot的插件需要放在docker插件前面
application.yml
spring:
profiles:
active:
- beta
application-beta.yml
logging:
level:
org.springframework: INFO app:
env: beta
application-prod.yml
logging:
level:
org.springframework: INFO app:
env: prod
编译镜像命令
mvn install dockerfile:build
查看镜像 docker images
启动命令,注意JAVA_OPSTS
分别为spring的环境配置,JVM远程调试和JMX命令
docker run \
-e "JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=y -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9110
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=127.0.0.1 " \
-e "SPRING_PROFILES_ACTIVE=prod" \
--init \
-p 8080:8080 \
-p 9110:9110 \
-p 9010:9010 \
-p 5005:5005 \
-it \
zzzzz/boot-demo:1.0
springboot-dokcer的更多相关文章
- Eclipse Springboot项目Dokcer
配置好Dockerfile FROM openjdk:8-jdk-alpine ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOIN ...
- Docker运行mysql,redis,oracle容器和SpringBoot项目
dokcer运行SpringBoot项目 from frolvlad/alpine-oraclejdk8:slim VOLUME /tmp ADD target/demo-0.0.1-SNAPSHOT ...
- docker-compose 部署 Vue+SpringBoot 前后端分离项目
一.前言 本文将通过docker-compose来部署前端Vue项目到Nginx中,和运行后端SpringBoot项目 服务器基本环境: CentOS7.3 Dokcer MySQL 二.docker ...
- 把java(springboot)程序打包docker镜像
前言:要在docker运行java(jar包)程序,就要把程序打包成docker镜像(以下简称镜像),可以先理解为镜像就是jar包 打包需要程序代码,java本身的打包环境(包括jdk和maven), ...
- Docker运行Mysql,Redis,SpringBoot项目
Docker运行Mysql,Redis,SpringBoot项目 1.docker运行mysql 1.1拉取镜像 1.2启动容器 1.3进入容器 1.4开启mysql 1.5设置远程连接 1.6查看版 ...
- 解决 Springboot Unable to build Hibernate SessionFactory @Column命名不起作用
问题: Springboot启动报错: Caused by: org.springframework.beans.factory.BeanCreationException: Error creati ...
- 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo
Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...
- Springboot搭建web项目
最近因为项目需要接触了springboot,然后被其快速零配置的特点惊呆了.关于springboot相关的介绍我就不赘述了,大家自行百度google. 一.pom配置 首先,建立一个maven项目,修 ...
- Java——搭建自己的RESTful API服务器(SpringBoot、Groovy)
这又是一篇JavaWeb相关的博客,内容涉及: SpringBoot:微框架,提供快速构建服务的功能 SpringMVC:Struts的替代者 MyBatis:数据库操作库 Groovy:能与Java ...
- 解决 SpringBoot 没有主清单属性
问题:SpringBoot打包成jar后运行提示没有主清单属性 解决:补全maven中的bulid信息 <plugin> <groupId>org.springframewor ...
随机推荐
- C/S架构和B/S架构
本文内容整理自http://blog.csdn.net/tennysonsky/article/details/45062079 C/S架构和B/S架构是两种颇具影响力的软件体系结构.C/S是一种历史 ...
- PR5
修改字幕的两种方式
- NeighboringCellInfo.aidl
在src下先建立包名为android.telephony(右键src > new > package,create package-info.java打钩),然后右键刚建的android. ...
- oracle 拆分字符串并转换为表
使用函数的方式 1. 创建的函数以及类型如下: CREATE OR REPLACE TYPE str_split IS TABLE OF VARCHAR2 (4000);CREATE OR REPLA ...
- x86函数调用约定
以下摘自<IDA Pro>,貌似有一些细节之处没有交代清楚呢,需要进一步思考.实践. 了解栈帧的基本概念后,接下来详细介绍它们的结构.下面的例子涉及x86体系结构和与常见的x86编译器(如 ...
- RAC7——vip的理解
VIP特点: 1 VIP是在clusterware安装最后阶段,通过脚本VIPCA创建的: 2 VIP作为一个Nodeapps类型的CRS Resource注册到OCR中,并由CRS维护状态: 3 V ...
- Thread.currentThread()与this的区别
Thread.currentThread()与this的区别: Thread.currentThread()方法返回的是对当前正在执行的线程对象的引用,this代表的是当前调用它所在函数所属的对象的引 ...
- thinkPHP5 引入模板
有三种方法:第一种: 直接使用 return view(); 助手函数第二种: use think\View; class Admin extends View 见下第三种: use think\Co ...
- go http 传递json数据
上篇博文中简单介绍了Go HTTP的Server 和Client.本文介绍如何在HTTP中传递json格式的数据. Server package main import ( "encodin ...
- TroubleShoot: Enable Developer Mode in Windows 10 Insider Preview Build 10074
There is a known issue in Windows 10 Insider Preview build 10074 (see here). Developers cannot enabl ...