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 an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.

WRITTEN BY Martuj Nadaf
Comments