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

Established in 2012, CloudThat is an award-winning company and the first in India to offer cloud training and consulting services for individuals and enterprises worldwide. Recently, it won Google Cloud’s New Training Partner of the Year Award for 2025, becoming the first company in the world in 2025 to hold awards from all three major cloud giants: AWS, Microsoft, and Google. CloudThat notably won consecutive AWS Training Partner of the Year (APJ) awards in 2023 and 2024 and the Microsoft Training Services Partner of the Year Award in 2024, bringing its total award count to an impressive 12 awards in the last 8 years. In addition to this, 20 trainers from CloudThat are ranked among Microsoft’s Top 100 MCTs globally for 2025, demonstrating its exceptional trainer quality on the global stage.  

As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, Google Cloud Platform Partner, and collaborator with leading organizations like HPE and Databricks, CloudThat has trained over 850,000 professionals across 600+ cloud certifications, empowering students and professionals worldwide to advance their skills and careers. 

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!