0
0
Dockerdevops~30 mins

Deploying from CI/CD pipeline in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Deploying from CI/CD pipeline
📖 Scenario: You work in a team that builds a simple web application using Docker containers. Your team wants to automate the deployment process so that every time new code is ready, it automatically builds and deploys the Docker container using a CI/CD pipeline.This project will guide you through creating a basic Docker setup and a simple CI/CD pipeline script to deploy your container.
🎯 Goal: Build a Docker image for a simple web app and write a CI/CD pipeline script that builds and deploys the Docker container automatically.
📋 What You'll Learn
Create a Dockerfile for a simple web app
Define a variable for the Docker image name
Write a shell script to build and deploy the Docker image
Print the deployment status
💡 Why This Matters
🌍 Real World
Automating Docker container deployment is common in software teams to speed up delivery and reduce manual errors.
💼 Career
Knowing how to create Docker images and automate deployment with scripts is a key skill for DevOps engineers and developers working with containers.
Progress0 / 4 steps
1
Create a Dockerfile for a simple web app
Create a file named Dockerfile with these exact contents:
FROM nginx:alpine
COPY ./html /usr/share/nginx/html
This will use the nginx alpine image and copy your web files to the container.
Docker
Need a hint?

Think of the Dockerfile as a recipe. The first line picks the base image, and the second line copies your website files inside the container.

2
Define a Docker image name variable
In a new file named deploy.sh, create a variable called IMAGE_NAME and set it to mywebapp:latest.
Docker
Need a hint?

Variables in shell scripts are set with NAME=value without spaces.

3
Write a shell script to build and deploy the Docker image
In the deploy.sh file, add commands to build the Docker image using docker build -t $IMAGE_NAME . and then run the container with docker run -d -p 8080:80 $IMAGE_NAME.
Docker
Need a hint?

Use docker build to create the image and docker run to start the container in detached mode.

4
Print the deployment status
At the end of deploy.sh, add a line to print Deployment of $IMAGE_NAME completed successfully! using echo.
Docker
Need a hint?

Use echo to print messages in shell scripts.