This project sets up a containerized environment for running a web application with multiple services, using Docker and Docker Compose. The project is configured to run on Vagrant for local development and testing. This README outlines the steps for setting up, running, and testing the project.
The project includes the following services:
- MySQL (Database Service): Version 8.0.33
- Memcache (Database Caching Service): Version 1.6
- RabbitMQ (Message Broker/Queue Service): Version 4.0
- JDK (Java Development Kit): JDK 21
- Maven: Version 3.9.9
- Tomcat (Application Service): Version 10 with JDK 21
- Nginx (Web Server): Version 1.27
Ensure you have the following software installed in your development environment:
- Vagrant: To set up and manage the virtual environment.
- Docker: For containerizing the services.
- Docker Compose: To orchestrate multiple containers.
The following base images from Docker Hub will be used for the respective services:
- MySQL:
mysql:8.0.33
- Memcache:
memcache:latest
- RabbitMQ:
rabbitmq:latest
- Maven:
maven:3.9.9-eclipse-temurin-21-jammy
- Tomcat:
tomcat:10-jdk21
- Nginx:
nginx:latest
For each service, a Dockerfile
is created to customize the container images. This may involve setting environment variables, configuring volumes, or adding necessary dependencies.
Example for customizing MySQL:
FROM mysql:8.0.33
ENV MYSQL_ROOT_PASSWORD=rootpassword
ENV MYSQL_DATABASE=myapp_db
The docker-compose.yml
file orchestrates the services, linking them together to form a complete system.
services:
vprodb:
build:
context: ./Docker-files/db
images: routparesh/vprodb
container_name: vprodb
ports:
- '3306:3306'
volumes:
- vprodbdata: /var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=vprodbpass
vprocache01:
images: memcached
container_name: vprocache01
ports:
- '11211:11211'
vpromq01:
images: rabbitmq
ports:
- '5672:5672'
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest
vproapp:
build:
context: ./Docker-files/app
images: routparesh/vproapp
container_name: vproapp
ports:
- '8080:8080'
volumes:
- vproappdata: /usr/local/tomcat/webapps
vproweb:
build:
context: ./Docker-files/web
images: routparesh/vproweb
container_name: vproweb
ports:
- '80:80'
volumes:
vprodbdata: {}
vproappdata: {}
-
Test Locally:
- Bring up the services using Docker Compose:
docker-compose up --build
- Ensure all services are running and interacting correctly.
-
Host Images on Docker Hub:
- After testing, push your custom images to Docker Hub:
docker tag <image_id> <dockerhub_username>/<repository_name>:<tag> docker push <dockerhub_username>/<repository_name>:<tag>
To run this setup within a Vagrant environment, create a Vagrantfile
with the appropriate configurations:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/jammy64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.provision "docker" do |d|
d.pull_images "mysql:8.0.33", "memcache:latest", "rabbitmq:latest", "nginx:latest"
end
end
Then run:
vagrant up
This will set up the Vagrant virtual machine with Docker installed and ready to run your containers.
This containerization project demonstrates how to set up a multi-container environment for an application using Docker, Docker Compose, and Vagrant. The services are designed to interact with one another, providing a scalable and modular environment for development and testing.