FROM java:8-jre-alpine
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/' /etc/apk/repositories
RUN apk add --no-cache --update-cache bash
#VOLUME /tmp
ADD *.jar app.jar
RUN sh -c 'touch /app.jar'
RUN echo $(date) > /image_built_at
ENTRYPOINT ["java","-Duser.timezone=GMT+08","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar","--spring.profiles.active=${SPRING_PROFILES_ACTIVE}"]
dockerfile具体怎么用的 自行百度
文件放置在main/docker下
pom文件配置
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!-- docker -->
<docker.image.prefix>registry.cn-hangzhou.aliyuncs.com/test</docker.image.prefix>
<docker.image.name>service-name</docker.image.name>
<docker.image.tag>${version}</docker.image.tag>
<!-- other versions -->
<swagger.version>2.6.1</swagger.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<imageName>${docker.image.prefix}/${docker.image.name}</imageName>
<imageTags>
<imageTag>${docker.image.tag}</imageTag>
</imageTags>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.20.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
maven打包docker镜像
打包命令需要在当前项目根目录下执行
mvn clean package -Dmaven.test.skip=true docker:build
打包成功后显示
下一步就是推送到阿里云镜像仓库
命令:docker push registry.cn-hangzhou.aliyuncs.com/mmt/device-control:0.0.1-api