12

I'm using the jenkins/jenkins:lts image at the moment. It runs fine and does everything I want to expect one thing. I want it to run Maven goals in the build steps. The problem is that there is not maven installed in the jenkins container environment.

So I want to extend the mentioned image to run an apt-get install maven.

My solution:

FROM "jenkins/jenkins:lts
USER root
RUN /bin/bash -c "apt-get install maven"

Will this be enough? I assume that all RUN and ENTRYPOINT steps of the jenkins image will run by itself and I do not need to re-execute them in my Dockerfile right?

xetra11
  • 7,671
  • 14
  • 84
  • 159

4 Answers4

12

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

pitchblack408
  • 2,913
  • 4
  • 36
  • 54
11

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
Bukharov Sergey
  • 9,767
  • 5
  • 39
  • 54
  • Worked! executing `docker-compose up` with my new image yields `ERROR: pull access denied for jenkins/jenkins-maven, repository does not exist or may require 'docker login'` - did I miss something? – xetra11 Sep 05 '17 at 10:42
  • show me please `docker build` command arguments for jenkins-maven image – Bukharov Sergey Sep 05 '17 at 10:53
  • `docker build -t jenkins-maven .` – xetra11 Sep 05 '17 at 10:54
  • 1
    Probably in `docker-compose.yml` image has name `jenkins/jenkins-maven`. But you built image `jenkins-maven`. Names must be the same. – Bukharov Sergey Sep 05 '17 at 11:11
  • 4
    I ran the command `bash -c "apt-get update && install -y maven"` in docker-compose and I got the error `E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)`. I tried with sudo as well but `bash: sudo: command not found`. Any ideas how can I run this? – Alex Pavlov Jun 08 '18 at 08:28
  • @AlexPavlov, take a look at my post below. It is more detailed. I was having a similar issue. – pitchblack408 Oct 26 '18 at 17:39
5

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.

  • This doesn't really answer the question at hand. It is possible to create a image from a dockerfile with desired tools included. – pitchblack408 Oct 26 '18 at 17:41
2

Works file for me

FROM jenkins/jenkins:lts
USER root
RUN apt-get update && apt-get install -y maven
Arthur Silva
  • 81
  • 1
  • 1
  • 6