π Day 13 of 30 Days DevOps Interview Preparation: Deploy Docker App via CI/CD

Series: 30 Days DevOps Interview Preparation
Author: Tathagat Gaikwad
In the DevOps world, one of the most common real-world tasks is packaging applications using Docker and automating deployments with CI/CD pipelines. Mastering this concept not only makes you job-ready but also helps you answer many DevOps interview questions with confidence.
πΉ Theoretical Foundations
1. What is Docker in DevOps?
Docker is a containerization platform that allows you to package an application with all its dependencies into a lightweight container. This ensures the app runs the same way regardless of where itβs deployed β developer laptop, testing server, or cloud.
2. Why CI/CD with Docker?
CI/CD (Continuous Integration and Continuous Deployment/Delivery) automates the building, testing, and deployment of code. When combined with Docker, it ensures:
β Consistency across environments
β Faster deployments with pre-built images
β Rollback capabilities (by reverting to previous images)
β Scalability when deployed on Kubernetes, ECS, or Swarm
πΉ Typical CI/CD Pipeline for a Dockerized App
Hereβs the high-level flow of deploying a Docker app with CI/CD:
Code Commit β Developer pushes changes to GitHub/GitLab.
Pipeline Triggered β Jenkins / GitHub Actions / GitLab CI detects changes.
Build Stage β Application is containerized using a Dockerfile.
Test Stage β Run automated tests inside the container.
Push Stage β Push Docker image to container registry (Docker Hub, AWS ECR).
Deploy Stage β Deploy the containerized app to staging or production.
πΉ Practical Example β Deploying Docker App with GitHub Actions
Letβs walk through an example where we deploy a simple Node.js Docker app via GitHub Actions.
Step 1: Dockerfile
# Use Node.js base image
FROM node:18-alpine
# Set working directory
WORKDIR /app
# Copy package.json and install dependencies
COPY package*.json ./
RUN npm install
# Copy source code
COPY . .
# Expose port
EXPOSE 3000
# Run the app
CMD ["npm", "start"]
Step 2: GitHub Actions Workflow (.github/workflows/docker-ci.yml
)
name: CI/CD Pipeline for Docker App
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
run: docker build -t my-docker-user/devops-app:latest .
- name: Push Docker Image to Docker Hub
run: docker push my-docker-user/devops-app:latest
Step 3: Deploy to AWS EC2 (Example Command)
On the EC2 instance, pull the latest image and run:
docker pull my-docker-user/devops-app:latest
docker stop devops-app || true
docker rm devops-app || true
docker run -d -p 80:3000 --name devops-app my-docker-user/devops-app:latest
πΉ Interview Preparation β Detailed Q&A
Q1. Why do we use Docker in CI/CD pipelines?
π To ensure the application runs consistently across environments, with reduced dependency issues. It makes testing, building, and deployment reproducible.
Q2. Difference between CI and CD?
CI (Continuous Integration): Merges code changes, builds Docker images, and runs automated tests.
CD (Continuous Deployment/Delivery): Pushes tested images to production automatically (or with approval).
Q3. How do you optimize Docker builds in CI/CD?
π Use multi-stage builds, leverage caching, use smaller base images (e.g., alpine
), and .dockerignore
to reduce context size.
Q4. How do you handle secrets when deploying Docker apps?
π Store them in a secure system like AWS Secrets Manager, HashiCorp Vault, or CI/CD toolβs secret store (never hardcode in Dockerfiles).
Q5. What deployment strategies can you use with Docker apps?
π Blue-Green Deployment, Canary Releases, and Rolling Updates to ensure zero-downtime deployments.
πΉ Key Takeaways
Docker + CI/CD = speed, consistency, and scalability.
Automating builds and deployments reduces human error and increases reliability.
Be interview-ready with strong knowledge of pipelines, registries, and deployment strategies.
π‘ What CI/CD tool do you prefer for Docker deployments β Jenkins, GitHub Actions, or GitLab CI? Share your thoughts!
#DevOps #Docker #CICD #AWS #DevOpsInterviewPreparation #Hashnode
Subscribe to my newsletter
Read articles from Tathagat Gaikwad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
