2.1 KiB
2.1 KiB
Docker Web Application Deployment
The application consists of two services:
- Web Service (Nginx):
- Uses the official Nginx image.
- Listens on port 80 inside the container and is mapped to host port 8080.
- Database Service (MySQL 5.7):
- Uses the official MySQL 5.7 image.
- Configured with a root password and a default database.
- Persists its data using the named volume
mysql-data
.
Files Overview
- prepare-app.sh:
- Creates the required Docker network (
myapp-net
) and persistent volume (mysql-data
).
- Creates the required Docker network (
- docker-compose.yaml:
- Defines the two services along with their ports, environment variables, volumes, and restart policies.
- start-app.sh:
- Starts the services using Docker Compose in detached mode.
- Displays the URL to access the web service.
- stop-app.sh:
- Stops the running containers without deleting the persistent volume.
- remove-app.sh:
- Removes all the created resources (containers, network, and volume) from the deployment.
Deployment Instructions
-
Preparation:
- Ensure Docker and Docker Compose are installed.
- Make the scripts executable:
chmod +x prepare-app.sh start-app.sh stop-app.sh remove-app.sh
- Run the preparation script:
./prepare-app.sh
-
Starting the Application:
- Launch the services by running:
./start-app.sh
- Open your web browser and navigate to http://localhost:8080 to see the Nginx welcome page.
- Launch the services by running:
-
Stopping the Application:
- Stop the services without losing data:
./stop-app.sh
- Stop the services without losing data:
-
Removing the Application:
- To completely remove all deployed resources, run:
./remove-app.sh
- To completely remove all deployed resources, run:
Notes
- The application uses an external network (
myapp-net
) and a persistent volume (mysql-data
) that are created inprepare-app.sh
. - The Nginx container depends on the MySQL container to demonstrate inter-service communication within the
myapp-net
network. - Containers are configured to restart on failure.