extend jenkins image to install maven

According to the documentation, this would be in your dockerfile

FROM jenkins/jenkins:lts
# if we want to install via apt
USER root
RUN apt-get update && apt-get install -y maven
# drop back to the regular jenkins user - good practice
USER jenkins

Assuming your docker file is in your current directory this is how you would build the image and install in your local docker repo

docker build -t jenkins-maven .

For more information

https://github.com/jenkinsci/docker

After installing maven this way, the mvn version will probably be older than what you need. When I ran this, it was Apache Maven 3.3.9


Here is the simplest way to install maven into docker:

  1. Connect to docker with root privilages

    sudo docker exec -u root -t -i [container-id] bash

  2. update and install maven

    apt-get update & apt-get install

That's it.


you need to update package cache before install, and don't miss -y for apt-get install.

FROM jenkins/jenkins:lts
RUN apt-get update && apt-get install -y maven