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%
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
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 Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, AWS GenAI Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, Amazon ECS Service Delivery Partner, AWS Glue Service Delivery Partner, Amazon Redshift Service Delivery Partner, AWS Control Tower Service Delivery Partner, AWS WAF Service Delivery Partner, Amazon CloudFront Service Delivery Partner, Amazon OpenSearch Service Delivery Partner, AWS DMS Service Delivery Partner, AWS Systems Manager Service Delivery Partner, Amazon RDS Service Delivery Partner, AWS CloudFormation Service Delivery Partner, AWS Config, Amazon EMR and many more.

WRITTEN BY Martuj Nadaf
Comments