title: dockerizing Spring Boot Application error: Error: Invalid or corrupt jarfile /app.jar
body: <p>I'm starting working with docker and I'm trying to dockerize my Spring boot Application. I generated this using spring initializr. I'm working with maven. My DockerFile looks like this:</p>
  
  <pre><code>FROM java:8-jdk-alpine
  
  COPY ${JAR_FILE} app.jar
  
  WORKDIR /usr/app
  
  EXPOSE 8080
  ENTRYPOINT ["java","-jar","/app.jar"]
  </code></pre>
  
  <p>It's pretty simple. </p>
  
  <p>I executed the next commands:</p>
  
  <pre><code>docker build -t shortenurl .
  </code></pre>
  
  <p>I can see the image in the console with docker images:</p>
  
  <p><a href="https://i.stack.imgur.com/A4tOf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A4tOf.png" alt="enter image description here"></a></p>
  
  <p>But when I try to run the image with the command: <code>docker run -p 8080:8080 shortenurl</code> I got this error message: Error: Invalid or corrupt jarfile /app.jar</p>
  
  <p>I've tried different configurations but not pretty sure. Any advice?</p>
  
  <p>Thanks.</p>
  
  <p>This is my plugin pom.xml plugins section:</p>
  
  <pre><code>       &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;com.spotify&lt;/groupId&gt;
                  &lt;artifactId&gt;docker-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;0.2.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;imageName&gt;${docker.image.prefix}/${project.artifactId}&lt;/imageName&gt;
                      &lt;dockerDirectory&gt;src/main/docker&lt;/dockerDirectory&gt;
                      &lt;resources&gt;
                          &lt;resource&gt;
                              &lt;directory&gt;${project.build.directory}&lt;/directory&gt;
                              &lt;include&gt;${project.build.finalName}.jar&lt;/include&gt;
                          &lt;/resource&gt;
                      &lt;/resources&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
  </code></pre>
  
  <p>This is my log after the command:docker build -t shortenurl .</p>
  
  <pre><code>$ docker build -t shortenurl .
  Sending build context to Docker daemon  32.89MB
  Step 1/5 : FROM java:8-jdk-alpine
   ---&gt; 3fd9dd82815c
  Step 2/5 : COPY ${JAR_FILE} app.jar
   ---&gt; 248aa4be697d
  Step 3/5 : WORKDIR /usr/app
   ---&gt; Running in 5fcd71c548af
  Removing intermediate container 5fcd71c548af
   ---&gt; bc344b970b11
  Step 4/5 : EXPOSE 8080
   ---&gt; Running in 46b4e4f8e9b7
  Removing intermediate container 46b4e4f8e9b7
   ---&gt; 6b4f55a86a23
  Step 5/5 : ENTRYPOINT ["java","-jar","/app.jar"]
   ---&gt; Running in 838a6052f4c8
  Removing intermediate container 838a6052f4c8
   ---&gt; 7d7d272ea42d
  Successfully built 7d7d272ea42d
  Successfully tagged shortenurl:latest
  SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
  </code></pre>