简体   繁体   中英

Generate docker image by maven plugin

I have manually written dockerfile but now I need configure maven to create that file and build image. I'm trying do it with spotify's maven plugin.

Here is dockerfile which is written by me and it works:

FROM tomcat:8.0-jre8
RUN rm -rvf /usr/local/tomcat/webapps/ROOT
COPY ./context.xml /usr/local/tomcat/conf/
COPY /target/brainis-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/ROOT.war
CMD ["catalina.sh", "run"]
EXPOSE 8080

I need ensure my maven plugin generate same docker file before build image. Can you tell me please how to achieve it? My current configuration generates only first command FROM tomcat:8.0-jre8 , how to configure rest of that file in maven?

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <configuration>
        <imageName>spring-tomcat</imageName>
        <baseImage>tomcat:8.0-jre8</baseImage>
    </configuration>
</plugin>

You need to add your Dockerfile to your codebase, ie /src/main/docker/Dockerfile and reference it from Spotify's Maven plugin this way:

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>${docker.plugin.version}</version>
    <configuration>
        <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
        <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
        <resources>
            <resource>
                <targetPath>/</targetPath>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.war</include>
            </resource>
        </resources>
    </configuration>
</plugin>

The last part, resources, places the docker build base path in whichever folder you want it, ie /target and which files to include.

That will run your whole Dockerfile script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM