Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hw1 #941

Open
wants to merge 11 commits into
base: DModesov/main
Choose a base branch
from
Open

hw1 #941

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
COMPOSE_PROJECT_NAME=COMPOSE_PROJECT_NAME

MYSQL_DATABASE=my_db
MYSQL_USER=my_db
MYSQL_PASSWORD=123
MYSQL_ROOT_PASSWORD=123

REDIS_PASSWORD=123

INTERFACE=0.0.0.0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.DS_Store
.AppleDouble
.LSOverride
.env
3 changes: 3 additions & 0 deletions code/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

phpinfo();
83 changes: 83 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# версия синтаксиса
version: '3'

# в этом блоке мы описываем контейнеры, которые будут запускаться
services:
#контейнер с Nginx
nginx:
build:
context: ./nginx
dockerfile: Dockerfile
image: myapp/nginx
container_name: webserver
# проброс портов
ports:
- "80:80"
volumes:
- ./code:/data/mysite.local
networks:
- app-network

#Контейнер с PHP-FPM, назовём его app
app:
# Если нет секции build, то система будет искать образ в репозиториях
build:
context: ./fpm
dockerfile: Dockerfile
image: myapp/php # имя будущего образа
container_name: app # имя контейнера после запуска
volumes:
- ./code:/data/mysite.local
# мы можем создать для контейнеров внутреннюю сеть
networks:
- app-network

memcached:
image: memcached:latest
container_name: myapp/memcached
volumes:
- ./cache:/var/lib/memcached
networks:
- app-network
stdin_open: true
tty: true
restart: unless-stopped

redis:
image: redis:latest
container_name: myapp/redis
volumes:
- ./redis:/var/lib/redis
environment:
- REDIS_PASSWORD=${REDIS_PASSWORD}
- REDIS_PORT=6379
- REDIS_DATABASES=16
networks:
- app-network

mysql:
build:
context: ./mysql
dockerfile: Dockerfile
image: myapp/mysql
container_name: db_mysql
volumes:
- ./mysql/data:/var/lib/mysql
ports:
- '${INTERFACE}:3306:3306'
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
command: mysqld --user=root --sql-mode=""
networks:
- app-network
stdin_open: true
tty: true
restart: unless-stopped

#Docker Networks
networks:
app-network:
driver: bridge
20 changes: 20 additions & 0 deletions fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM php:8.2-fpm

# ставим необходимые для нормальной работы модули
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libonig-dev \
libzip-dev \
libmemcached-dev \
libmcrypt-dev \
&& docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip

COPY ./php.ini /usr/local/etc/php/conf.d/php-custom.ini

WORKDIR /data

VOLUME /data

CMD ["php-fpm"]
2 changes: 2 additions & 0 deletions fpm/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
session.save_handler = memcache
session.save_path = "tcp://memcache:11211"
11 changes: 11 additions & 0 deletions mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM mysql:8.0

LABEL org.opencontainers.image.source="https://github.com/bitrixdock/bitrixdock"

MAINTAINER vitams

COPY my.cnf /etc/mysql/conf.d/my.cnf

CMD ["mysqld"]

EXPOSE 3306
11 changes: 11 additions & 0 deletions mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[mysqld]
default-time-zone="+03:00"
innodb_file_per_table=1
innodb_flush_log_at_trx_commit=2
sync_binlog=0
# Try to replace O_DIRECT by O_DSYNC if you have "Operating system error number 22"
innodb_flush_method=O_DIRECT
transaction-isolation=READ-COMMITTED
binlog_cache_size=0
sql_mode=""

11 changes: 11 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nginx:latest

COPY ./hosts/mysite.local.conf /etc/nginx/conf.d/mysite.local.conf

WORKDIR /data

VOLUME /data

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
36 changes: 36 additions & 0 deletions nginx/hosts/mysite.local.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
server {
# указываем 80 порт для соединения
listen 80;
# нужно указать, какому доменному имени принадлежит наш конфиг
server_name mysite.local;

# задаём корневую директорию
root /data/mysite.local;

# стартовый файл
index index.php index.html;

# при обращении к статическим файлам логи не нужны, равно как и обращение к fpm
# http://mysite.local/static/some.png
location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}

# помним про единую точку доступа
# все запросы заворачиваются в корневую директорию root на index.php
location / {
try_files $uri $uri/ /index.php?$query_string;
}

# и наконец правило обращения к php-fpm
location ~* .php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass app:9000;
#fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Loading