Docker Series - Part 13: Dockerfile Deep Dive, Compose Magic & Real-World Tomcat Deployment

Table of contents

Welcome back to the Docker Zero to Advance series! In this session, we go full-throttle into real-world Docker applications. From launching Tomcat servers to automating builds with Dockerfile and Compose, we explore Docker in action with system-level control. If you're aiming to become confident with production-grade containers, this article is a must-read.
Installing Tomcat via Docker
When an image is not available locally, Docker automatically pulls it from Docker Hub.
curl http://<container-ip>:8080
Understanding Container Access
docker attach
works if the container has a shell.docker exec -it <container_id> bash
allows access to containers even without shell support.
Tomcat Web Page Hosting
Tomcat serves files from /usr/local/tomcat/webapps/ROOT/
. Place your index.html
here to serve custom content.
Creating Custom Tomcat Image
FROM tomcat:9.0
RUN mkdir /usr/local/tomcat/webapps/ROOT
COPY index.html /usr/local/tomcat/webapps/ROOT/
Build it:
docker build -t mytomcat:v1 .
docker run -dit mytomcat:v1
Verify with:
curl http://<container-ip>:8080
Docker-Compose Integration
Docker Compose simplifies multi-container orchestration. It can build and launch containers from Dockerfiles.
version: "3"
services:
webapp:
build: .
ports:
- "8081:8080"
Run with:
docker-compose up -d
COPY vs ADD in Dockerfile
COPY
only supports local file copying. ADD
supports both file copy and URL-based downloading or extracting TAR files.
FROM centos:7
ADD https://raw.githubusercontent.com/.../README.md /
Working with TAR Files
Create TAR:
tar -cf myweb.tar /website
Extract TAR:
tar -xf myweb.tar
Add TAR into image and extract it:
FROM centos:7
ADD myweb.tar /
Docker automatically extracts the archive during build.
Apache Web Server Image
FROM centos:7
RUN yum install httpd -y
COPY *.html /var/www/html/
EXPOSE 80
ENTRYPOINT ["httpd"]
CMD ["-DFOREGROUND"]
Launch:
docker run -dit -P myweb:v1
Access using exposed random port.
ENV Variables in Dockerfile
ENV NAME=vimal
Use inside the container:
echo $NAME
Final Thoughts: In this session, we touched on every vital Docker skill: building images, layering, running containers with Compose, exposing services, managing static files, and even working with compressed content. You're now ready to build, package, and deploy Dockerized web applications like a pro.
Subscribe to my newsletter
Read articles from Nitin Dhiman directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Nitin Dhiman
Nitin Dhiman
Self-taught DevOps enthusiast on a journey from beginner to pro. Passionate about demystifying complex tools like Docker, AWS, CI/CD & Kubernetes into clear, actionable insights. Fueled by curiosity, driven by hands-on learning, and committed to sharing the journey. Always building, always growing ๐