# How to build docker image in agent docker?

**URL:** <https://community.jenkins.io/t/how-to-build-docker-image-in-agent-docker/10337>\
**Category:** Using Jenkins\
**Tags:** question, docker\
**Created:** [October 24, 2023, 9:01am UTC](https://community.jenkins.io/t/how-to-build-docker-image-in-agent-docker/10337 "2023-10-24T09:01:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradhuang9999](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/bradhuang9999/32/5909_2.png) [@bradhuang9999](https://community.jenkins.io/u/bradhuang9999)\
**Post date:** [October 24, 2023, 9:01am UTC](https://community.jenkins.io/t/how-to-build-docker-image-in-agent-docker/10337/1 "2023-10-24T09:01:31Z")

</div>

I follow [Build a Java app with Maven](https://www.jenkins.io/doc/tutorials/build-a-java-app-with-maven/)

But after I build the jar by maven in DIND maven container, I can’t build docker image.

The error message is ‘script.sh: line 1: docker: not found’

Mayby I need to follow [Using Docker with Pipeline](https://www.jenkins.io/doc/book/pipeline/docker/)

**Jenkinsfile can not run:**

```auto
pipeline {
    agent {
        docker {
            image 'maven:3.9.5-eclipse-temurin-17-alpine' 
            args '-v /root/.m2:/root/.m2' 
        }
    }
    stages {
        stage('Checkout Git') {
            steps {
                sh 'git clone <your_git_repository_url> .'
            }
        }

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

        stage('Build Docker Image') {
            steps {
                sh 'docker build -t myorg/myapp:${BUILD_NUMBER} --build-arg JAR_FILE=target/*.jar .'
            }
        }
    }
}

```

I have already install docker jenkins plugin.  
So I can build image at build-in node

**Jenkinsfile can run:**

```auto
pipeline {
    agent any

    stages {
        stage('Checkout Git') {
            steps {
                sh 'git clone <your_git_repository_url> .'
            }
        stage('Build image') {
            steps {
                script {
                    dockerImage = docker.build registry + ":latest"
                }
            }
        }
        }
    }
}    

```
