How to build docker image in agent docker?

I follow 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

Jenkinsfile can not run:

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:

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"
                }
            }
        }
        }
    }
}