# Where is the documentation for "Building container" using Descriptive pipeline

**URL:** <https://community.jenkins.io/t/where-is-the-documentation-for-building-container-using-descriptive-pipeline/22655>\
**Category:** Using Jenkins\
**Tags:** docker\
**Created:** [October 30, 2024, 12:25pm UTC](https://community.jenkins.io/t/where-is-the-documentation-for-building-container-using-descriptive-pipeline/22655 "2024-10-30T12:25:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Padmahas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/padmahas/32/8954_2.png) [@Padmahas](https://community.jenkins.io/u/Padmahas)\
**Post date:** [October 30, 2024, 12:25pm UTC](https://community.jenkins.io/t/where-is-the-documentation-for-building-container-using-descriptive-pipeline/22655/1 "2024-10-30T12:25:54Z")

</div>

I found documentation for building containers [here](https://www.jenkins.io/doc/book/pipeline/docker/#building-containers) under " Advanced Usage with Scripted Pipeline".

But where can I find documentation for building containers for “Descriptive pipeline”?

Thank you.

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [October 31, 2024, 9:26am UTC](https://community.jenkins.io/t/where-is-the-documentation-for-building-container-using-descriptive-pipeline/22655/2 "2024-10-31T09:26:59Z")

</div>

For building containers using a Declarative Pipeline in Jenkins, you can refer to the official [Jenkins documentation on Declarative Pipeline syntax](https://www.jenkins.io/doc/book/pipeline/syntax/#declarative-pipeline).

Here is an untested example of how you could build and use Docker containers in a Declarative Pipeline:

```auto
pipeline {
    agent {
        any
    }
    stages {
        stage('Build') {
            steps {
                script {
                    // Build your application here
                    sh 'mvn clean install'
                }
            }
        }
        stage('Test') {
            steps {
                script {
                    // Run your tests here
                    sh 'mvn test'
                }
            }
        }
        stage('Build Docker Image') {
            steps {
                script {
                    // Build Docker image
                    sh 'docker build -t my-app:latest .'
                }
            }
        }
        stage('Push Docker Image') {
            steps {
                script {
                    // Push Docker image to registry
                    withCredentials([usernamePassword(credentialsId: 'dockerhub-credentials', usernameVariable: 'DOCKERHUB_USER', passwordVariable: 'DOCKERHUB_PASS')]) {
                        sh 'docker login -u $DOCKERHUB_USER -p $DOCKERHUB_PASS'
                        sh 'docker push my-app:latest'
                    }
                }
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Padmahas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/padmahas/32/8954_2.png) [@Padmahas](https://community.jenkins.io/u/Padmahas)\
**Post date:** [November 5, 2024, 3:00pm UTC](https://community.jenkins.io/t/where-is-the-documentation-for-building-container-using-descriptive-pipeline/22655/3 "2024-11-05T15:00:38Z")

</div>

Thank you @poddingue .

I had to use the sh ‘docker …’ command in a separate stage instead of first stage. OR else it will throw “docker not found” error.

I also got the same answer in the Jenkins Gitter chat.

Thank you.

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [November 6, 2024, 7:43am UTC](https://community.jenkins.io/t/where-is-the-documentation-for-building-container-using-descriptive-pipeline/22655/4 "2024-11-06T07:43:31Z")

</div>

Thanks for your feedback. 👍
