From 3dcf0d0a8149139829b8944f30de658416a2e261 Mon Sep 17 00:00:00 2001 From: Bohdan Krokhmal Date: Mon, 17 Mar 2025 18:29:00 +0100 Subject: [PATCH] init --- README.md | 25 +++++++++++++++++++++++++ docker-compose.yaml | 31 +++++++++++++++++++++++++++++++ prepare-app.sh | 19 +++++++++++++++++++ remove-app.sh | 5 +++++ start-app.sh | 5 +++++ stop-app.sh | 3 +++ 6 files changed, 88 insertions(+) create mode 100644 README.md create mode 100644 docker-compose.yaml create mode 100755 prepare-app.sh create mode 100755 remove-app.sh create mode 100755 start-app.sh create mode 100755 stop-app.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..6dc212c --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# MyApp Docker Deployment + +## Requirements +- Docker installed +- Docker Compose (optional) + +## Description +This application consists of a web service and a database service. The web service listens on port 5000 and interacts with the database service. + +## Networks and Volumes +- **myapp-network**: A bridge network for inter-container communication. +- **myapp-data**: A volume to persist database data. + +## Container Configuration +- **myapp-web**: Web service built from `./web` directory, exposes port 5000. +- **myapp-db**: MySQL database service using the official MySQL 5.7 image. + +## Instructions +- Prepare the application: `./prepare-app.sh` +- Start the application: `./start-app.sh` +- Stop the application: `./stop-app.sh` +- Remove the application: `./remove-app.sh` + +## Accessing the Application +Open a web browser and navigate to `http://localhost:5000`. diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..7f1ad00 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,31 @@ +version: '3.8' + +services: + web: + image: myapp-web + ports: + - "5000:5000" + networks: + - myapp-network + restart: on-failure + depends_on: + - db + + db: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: appdb + volumes: + - myapp-data:/var/lib/mysql + networks: + - myapp-network + restart: on-failure + +networks: + myapp-network: + external: true + +volumes: + myapp-data: + external: true diff --git a/prepare-app.sh b/prepare-app.sh new file mode 100755 index 0000000..4fd03c0 --- /dev/null +++ b/prepare-app.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# prepare-app.sh + +if ! docker network ls | grep -w myapp-net >/dev/null; then + docker network create myapp-net + echo "Created Docker network: myapp-net" +else + echo "Docker network myapp-net already exists." +fi + +if ! docker volume ls | grep -w mysql-data >/dev/null; then + docker volume create mysql-data + echo "Created Docker volume: mysql-data" +else + echo "Docker volume mysql-data already exists." +fi + +echo "Preparation complete." + diff --git a/remove-app.sh b/remove-app.sh new file mode 100755 index 0000000..b49773b --- /dev/null +++ b/remove-app.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo "Removing app ..." +docker rm myapp myapp-db +docker network rm myapp-net +docker volume rm myapp-data diff --git a/start-app.sh b/start-app.sh new file mode 100755 index 0000000..6a90913 --- /dev/null +++ b/start-app.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo "Running app ..." +docker run -d --name myapp-db --network myapp-net -v myapp-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password mysql:5.7 +docker run -d --name myapp --network myapp-net -p 5000:80 nginx +echo "The app is available at http://localhost:5000" diff --git a/stop-app.sh b/stop-app.sh new file mode 100755 index 0000000..43c21e5 --- /dev/null +++ b/stop-app.sh @@ -0,0 +1,3 @@ +#!/bin/bash +echo "Stopping app ..." +docker stop myapp myapp-db