0
0
Dockerdevops~30 mins

Building images in CI pipeline in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Building images in CI pipeline
📖 Scenario: You work in a team that uses Docker containers to package applications. Your team wants to automate building Docker images whenever new code is pushed. This helps deliver updates faster and with fewer errors.
🎯 Goal: Build a simple Docker image using a Dockerfile and automate the build process in a CI pipeline script.
📋 What You'll Learn
Create a Dockerfile with a base image and a simple command
Add a variable for the image tag
Write a command to build the Docker image using the tag variable
Print the Docker build command output
💡 Why This Matters
🌍 Real World
Automating Docker image builds in CI pipelines helps teams deliver software updates quickly and reliably.
💼 Career
Knowing how to build Docker images and automate builds is a key skill for DevOps engineers and developers working with containers.
Progress0 / 4 steps
1
Create a Dockerfile
Create a file named Dockerfile with these exact contents:
FROM alpine:3.18
CMD ["echo", "Hello from Docker image"]
Docker
Need a hint?

The Dockerfile must start with FROM alpine:3.18 and have a CMD that echoes the exact text.

2
Add an image tag variable
In a shell script file named build.sh, create a variable called IMAGE_TAG and set it to myapp:latest.
Docker
Need a hint?

Use IMAGE_TAG=myapp:latest exactly in your script.

3
Write Docker build command
In the build.sh script, add a command to build the Docker image using the IMAGE_TAG variable and the current directory as context. Use docker build -t $IMAGE_TAG ..
Docker
Need a hint?

Use the exact command docker build -t $IMAGE_TAG . to build the image.

4
Print build command output
Add a command to the build.sh script to print the message Docker image built with tag: $IMAGE_TAG after the build command.
Docker
Need a hint?

Use echo "Docker image built with tag: $IMAGE_TAG" to print the message.