Docker Community Forums

Share and learn in the Docker community.

Docker for java developement


(Maryem) #1

Hey there, I’m a beginner in Docker and i want to run a Java application in a docker container, I’m trying to install maven in my dockerfile, but when i press docker build -t username/name_of_app, I get an error : ( E: Unable to locate package maven
INFO[0004] The command [/bin/sh -c apt-get install maven] returned a non-zero code: 100 )

I don’t know how to solve this :frowning:

Any ideas are welcome :slight_smile:


(Sabin Basyal) #2

Please have a look over this official repo for maven: https://registry.hub.docker.com/_/maven/


(Maryem) #3

Thank you @sbasyal for your reply, I changed my dockerfile following the link you sent to me but I still get the same Error :’(


(Sabin Basyal) #4

I just tried and it is working. This is my Dockerfile

FROM maven:3

ADD pom.xml /home/pom.xml
WORKDIR /home

And this is my test pom.xml file I place in the same location as above Dockerfile:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
 
  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>
 
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Your test folder would look like this:

test
   |__ Dockerfile
   |__ pom.xml

Now, go to test and do docker build -t mvn-test .
Then, finally do docker run -P mvn-test:latest mvn package


(Maryem) #5

Thank you so much @sbasyal :slight_smile: It works
Cheers