- 项目目录结构
.
|-- docker-compose.yaml
|-- Dockerfile
|-- mvnw
|-- mvnw.cmd
|-- pom.xml
|-- README.md
|-- src
- pom配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
docker-maven插件(非必要,但可极大的丰富mvn对镜像的操作)
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
- DockerFile
FROM anapsix/alpine-java:8_server-jre_unlimited
MAINTAINER xxxxxxx@qq.com
ENV TZ=Asia/Shanghai
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /swagger-server
WORKDIR /swagger-server
EXPOSE 8080
ADD ./target/springboot-swagger-0.0.1-SNAPSHOT.jar ./
CMD sleep 10;java -Djava.security.egd=file:/dev/./urandom -jar springboot-swagger-0.0.1-SNAPSHOT.jar
- docker-compose.yaml
version: '2'
services:
swagger-server:
build:
context: .
restart: always
ports:
- 80:8080
container_name: c_swagger
hostname: my-host
image: i_swagger
- 编译打包步骤(不编排)
# 1.先用maven编译-打包源码
mvn clean package
# 2. 用docker单独构件镜像
docker build -t i_swagger:v0.1 .
# 3. 基于打好的镜像启动一个容器
docker run -d -p 80:8080 i_swagger
- 编译打包步骤(编排)
# 1.先用maven编译-打包源码
mvn clean package
# 2.用docker-compose构件镜像
docker-compose build .
# 3.用docker-compose编排启动容器
docker-compose up -d