Docker for java developement

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:

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

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

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

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