0
0
Jenkinsdevops~10 mins

Building Docker images in pipeline in Jenkins - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the Docker build step in a Jenkins pipeline.

Jenkins
stage('Build Docker Image') {
  steps {
    script {
      dockerImage = docker.[1]('myapp:latest')
    }
  }
}
Drag options to blanks, or click blank then click option'
Abuild
Bpull
Crun
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' instead of 'build' will try to run a container, not build an image.
Using 'push' before building the image will cause an error.
2fill in blank
medium

Complete the code to push the built Docker image to a registry in the Jenkins pipeline.

Jenkins
stage('Push Docker Image') {
  steps {
    script {
      dockerImage.[1]()
    }
  }
}
Drag options to blanks, or click blank then click option'
Apull
Bbuild
Cpush
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build' here will try to build again instead of pushing.
Using 'pull' will try to download an image, not upload.
3fill in blank
hard

Fix the error in the Jenkins pipeline code to correctly build a Docker image with a custom Dockerfile path.

Jenkins
stage('Build Custom Docker Image') {
  steps {
    script {
      dockerImage = docker.[1]('myapp:custom', '-f Dockerfile.custom .')
    }
  }
}
Drag options to blanks, or click blank then click option'
Arun
Bbuild
Cpush
Dpull
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' will try to start a container instead of building.
Using 'push' will try to upload an image that may not exist yet.
4fill in blank
hard

Fill both blanks to build and push a Docker image with a tag in a Jenkins pipeline.

Jenkins
stage('Build and Push') {
  steps {
    script {
      dockerImage = docker.[1]('myapp:[2]')
      dockerImage.push()
    }
  }
}
Drag options to blanks, or click blank then click option'
Abuild
Blatest
Cdev
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' instead of 'build' will cause an error.
Using 'latest' tag when you want a development version.
5fill in blank
hard

Fill all three blanks to build a Docker image, tag it, and push it to a registry in a Jenkins pipeline.

Jenkins
stage('Build, Tag, and Push') {
  steps {
    script {
      dockerImage = docker.[1]('myapp:[2]')
      dockerImage.[3]('myregistry.com/myapp:[2]')
    }
  }
}
Drag options to blanks, or click blank then click option'
Abuild
Bpush
Ctag
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of build, tag, and push.
Using 'run' instead of 'tag' or 'push'.