DevOps

3 Mins Read

Automating Web App Deployment with Docker Using Bash

Voiced by Amazon Polly

In this blog, we’ll walk through a hands-on lab using a Bash script to automate Docker image creation, container deployment, volume/network setup, and push the image to Docker Hub. By the end, you’ll have a live NGINX-based web app running with a custom HTML page—all through automation.

Want to save money on IT costs?

  • Migrate to cloud without hassles
  • Save up to 60%
Get Started with Free AWS Credits

Key points

  • Automate Docker image creation using Bash
  • Embed custom messages in web pages
  • Build and push Docker images to Docker Hub
  • Create Docker volumes and networks
  • Run containers with mounted volumes
  • Access your containerized app via a browser

Prerequisites

Before starting, make sure you have:

  • Docker installed
  • A Docker Hub account (with credentials handy)
  • Basic Bash scripting knowledge
  • Internet connection for image pulls and push

Lab Directory Structure

docker-web-app/

├── index.html

└── Dockerfile

  • Log in to the Ubuntu server and check the Docker version.

  • Log in to Docker Hub

  • Create a file auto_docker_web.sh with the following eight steps content.

  • Provide execute permission on the file.

  • Run the script with custom content as follows.

  • Now it’s time to access the web application.

You can access on

 

Steps included

Step 0: Configuration Block

  • DOCKER_USERNAME: Your Docker Hub username.
  • APP_NAME: Your application name.
  • CUSTOM_MESSAGE: Message displayed on the webpage.
  • PORT: The host port to expose.
  • VOLUME_NAME: Docker volume for persistent data.
  • NETWORK_NAME: Docker network to isolate the app.
  • TAG: Docker image tag.

Step 1: Create Project Directory

Creates and enters the project folder.

Step 2: Generate index.html

This step dynamically creates an HTML file with a custom heading.

Step 3: Create a Dockerfile

Uses a lightweight NGINX image

Copies your custom HTML

Step 4: Build Docker Image

Builds a Docker image with the tag and pushes it to Docker Hub.

Step 5: Docker Hub Login

You’ll be prompted for your Docker Hub credentials.

Step 6: Push Image to Docker Hub

Uploads your image to Docker Hub for future reuse or team access.

Step 7: Create Docker Volume & Network

Volumes persist your logs or data.

Networks enable multi-container setups (like DB + Web App).

Step 8: Run the Container

Conclusion

You now know how to fully automate the deployment of a static web app using:

  • Bash scripting
  • Docker images and containers
  • Docker volumes and networks
  • Pushing to Docker Hub
  • Serving over localhost

This type of automation is a powerful DevOps skill that lays the foundation for CI/CD, infrastructure as code, and container orchestration (like Kubernetes).

Train your workforce to leverage the cloud

  • Contemplating Migrating Workload to Cloud?
  • Here is a Hassle Free Solution
Get Started Now

About CloudThat

CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAWS GenAI Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery Partner AWS Microsoft Workload PartnersAmazon EC2 Service Delivery PartnerAmazon ECS Service Delivery PartnerAWS Glue Service Delivery PartnerAmazon Redshift Service Delivery PartnerAWS Control Tower Service Delivery PartnerAWS WAF Service Delivery PartnerAmazon CloudFront Service Delivery PartnerAmazon OpenSearch Service Delivery PartnerAWS DMS Service Delivery PartnerAWS Systems Manager Service Delivery PartnerAmazon RDS Service Delivery PartnerAWS CloudFormation Service Delivery PartnerAWS ConfigAmazon EMR and many more.

WRITTEN BY Martuj Nadaf

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!