Spring Boot中Dockerfile使用

weixin_33762321發表於2017-07-14
  • pom修改
<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>

    <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
            <execution>
                <id>copy-resources</id>
                <phase>validate</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${basedir}/target/</outputDirectory>
                    <resources>
                        <resource>
                            <directory>.docker</directory>
                            <filtering>true</filtering>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>
  • Dockerfile檔案
FROM java:8u111-jdk
ADD spring-boot-maven-docker.jar /opt/spring-boot-maven-docker/
EXPOSE 8080
WORKDIR /opt/spring-boot-maven-docker/
CMD ["java", "-jar", "spring-boot-maven-docker.jar"]
  • 生成映象檔案
    • Dockerfile和jar包放在同一個目錄下
    • docker build -t spring-boot .
  • 生成容器並啟動
    • docker run -itd -p 8090:8090 --name spring 1f7b9450a802
  • 詳細地址

相關文章