Загрузить файлы в «z1»
This commit is contained in:
parent
f187d4a92e
commit
76d8960bfb
15
z1/Dockerfile
Normal file
15
z1/Dockerfile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Используем официальный образ Nginx
|
||||||
|
FROM nginx:latest
|
||||||
|
|
||||||
|
# Копируем конфиг файлы в контейнер
|
||||||
|
COPY nginx/nginx.conf /etc/nginx/nginx.conf
|
||||||
|
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
# Копируем содержимое вашего веб-приложения в контейнер
|
||||||
|
COPY ./app /usr/share/nginx/html
|
||||||
|
|
||||||
|
# Открываем порт 80 для веб-сервера
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# Запускаем Nginx
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
67
z1/README.md
Normal file
67
z1/README.md
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# Docker Web Application with MySQL and Nginx
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
- Docker
|
||||||
|
- Docker Compose
|
||||||
|
|
||||||
|
## Description
|
||||||
|
This web application consists of two services:
|
||||||
|
1. A **web service** using Nginx to serve static HTML files.
|
||||||
|
2. A **database service** using MySQL, which persists its data in a Docker volume.
|
||||||
|
|
||||||
|
## Docker Volumes and Networks
|
||||||
|
- **Volume**: `db_data` - used to persist MySQL data.
|
||||||
|
- **Network**: `app-network` - internal network for the services to communicate.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
- **Nginx**: Serves static HTML files from the `/html` directory.
|
||||||
|
- **MySQL**: Configured with `MYSQL_ROOT_PASSWORD` and a default database `mydb`.
|
||||||
|
|
||||||
|
## How to Use
|
||||||
|
|
||||||
|
### Preparing the app
|
||||||
|
Run the following command to prepare the application:
|
||||||
|
```bash
|
||||||
|
./prepare-app.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Starting the app
|
||||||
|
To start the app, run:
|
||||||
|
```bash
|
||||||
|
./start-app.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
The app will be available at `http://localhost:5000`.
|
||||||
|
|
||||||
|
### Stopping the app
|
||||||
|
To stop the app, run:
|
||||||
|
```bash
|
||||||
|
./stop-app.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Removing the app
|
||||||
|
To remove all resources related to the app, run:
|
||||||
|
```bash
|
||||||
|
./remove-app.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Prepare the app
|
||||||
|
./prepare-app.sh
|
||||||
|
Preparing app...
|
||||||
|
|
||||||
|
# Start the app
|
||||||
|
./start-app.sh
|
||||||
|
Running app ...
|
||||||
|
The app is available at http://localhost:5000
|
||||||
|
|
||||||
|
# Stop the app
|
||||||
|
./stop-app.sh
|
||||||
|
Stopping app...
|
||||||
|
|
||||||
|
# Remove the app
|
||||||
|
./remove-app.sh
|
||||||
|
Removed app.
|
||||||
|
```
|
BIN
z1/Yan .zip
Normal file
BIN
z1/Yan .zip
Normal file
Binary file not shown.
23
z1/default.conf
Normal file
23
z1/default.conf
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# default.conf
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
# Путь до вашего веб-приложения
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html index.htm;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Для обработки ошибок
|
||||||
|
error_page 404 /404.html;
|
||||||
|
location = /404.html {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
}
|
31
z1/docker-compose.yml
Normal file
31
z1/docker-compose.yml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
version: "3.7"
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
volumes:
|
||||||
|
- ./app:/usr/share/nginx/html
|
||||||
|
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
|
||||||
|
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
restart: always
|
||||||
|
db:
|
||||||
|
image: mysql:5.7
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: example
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/mysql
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
app-network:
|
||||||
|
driver: bridge
|
||||||
|
|
2
z1/index.html
Normal file
2
z1/index.html
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
mkdir app
|
||||||
|
echo "<html><body><h1>Hello World! My name is Yan Kasabutski</h1></body></html>" > app/index.html
|
23
z1/nginx.conf
Normal file
23
z1/nginx.conf
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# nginx.conf
|
||||||
|
worker_processes 1;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
include mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
# Логирование
|
||||||
|
access_log /var/log/nginx/access.log;
|
||||||
|
error_log /var/log/nginx/error.log;
|
||||||
|
|
||||||
|
sendfile on;
|
||||||
|
tcp_nopush on;
|
||||||
|
tcp_nodelay on;
|
||||||
|
keepalive_timeout 65;
|
||||||
|
types_hash_max_size 2048;
|
||||||
|
|
||||||
|
include /etc/nginx/conf.d/*.conf;
|
||||||
|
}
|
8
z1/prepare-app.sh
Normal file
8
z1/prepare-app.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Включаем создание контейнеров
|
||||||
|
docker-compose build
|
||||||
|
|
||||||
|
# Создание сети и томов
|
||||||
|
docker network create app-network
|
||||||
|
docker volume create db_data
|
6
z1/remove-app.sh
Normal file
6
z1/remove-app.sh
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Удаляем все контейнеры, тома и сети
|
||||||
|
docker-compose down --volumes --remove-orphans
|
||||||
|
docker network rm app-network
|
||||||
|
docker volume rm db_data
|
7
z1/start-app.sh
Normal file
7
z1/start-app.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Запуск контейнеров в фоновом режиме
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# Выводим на каком порте доступно приложение
|
||||||
|
echo "The app is available at http://localhost:5000"
|
4
z1/stop-app.sh
Normal file
4
z1/stop-app.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Останавливаем все контейнеры
|
||||||
|
docker-compose down
|
Loading…
Reference in New Issue
Block a user