'Jenkins not building docker image, can't find the docker command

I'm trying to make Jenkins build and publish a docker image of my project after every successful build of my Maven Java project.

I have a Dockerfile and a Jenkinsfile at the root of the project.

Here's my Jenkinsfile?

pipeline {

    agent {
        docker {
            image 'maven:3-alpine'
            args '-v /root/.m2:/root/.m2'
        }
    }

    options {
        skipStagesAfterUnstable()
    }

    stages {
        stage('Build') {
            steps {
                sh 'mvn -B -DskipTests clean package'
            }
        }

        stage('Build image') {
            steps {
                script {
                    docker.withRegistry('http://localhost:5000') {
                        def customImage = docker.build("my-image:${env.BUILD_ID}")
                        customImage.push()
                    }
                }
            }
        }
    }

    post {
        always {
            archiveArtifacts artifacts: 'target/**/*.jar', fingerprint: true
        }
    }
}

When Jenkins tr to build this project, it returns the given error message:

+ docker build -t my-image:13 .

/var/jenkins_home/workspace/powertiss-eureka_master@tmp/durable-b9e45059/script.sh: line 1: docker: not found

Error

What am I doing wrong here?

*edit: My Dockerfile

FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY target/projectName-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]


Solution 1:[1]

The maven:3-alpine image most likely does not include Docker. You need to choose an image that has Docker included.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mpinheir