From 07c9432e19c418078ceffd7cf0bd750fb3caaffc Mon Sep 17 00:00:00 2001 From: Modesov Denis Date: Mon, 18 Nov 2024 13:02:14 +0400 Subject: [PATCH 01/11] hw1 --- .env.example | 10 ++++ .gitignore | 1 + code/index.php | 4 ++ docker-compose.yaml | 87 +++++++++++++++++++++++++++++++++++ fpm/Dockerfile | 20 ++++++++ fpm/php.ini | 2 + mysql/Dockerfile | 11 +++++ mysql/my.cnf | 11 +++++ nginx/Dockerfile | 11 +++++ nginx/hosts/mysite.local.conf | 36 +++++++++++++++ 10 files changed, 193 insertions(+) create mode 100644 .env.example create mode 100644 code/index.php create mode 100644 docker-compose.yaml create mode 100644 fpm/Dockerfile create mode 100644 fpm/php.ini create mode 100644 mysql/Dockerfile create mode 100644 mysql/my.cnf create mode 100644 nginx/Dockerfile create mode 100644 nginx/hosts/mysite.local.conf diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..9ae8f3bf0 --- /dev/null +++ b/.env.example @@ -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 diff --git a/.gitignore b/.gitignore index b28e598f1..f38c6f556 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .DS_Store .AppleDouble .LSOverride +.env \ No newline at end of file diff --git a/code/index.php b/code/index.php new file mode 100644 index 000000000..bcf0cea25 --- /dev/null +++ b/code/index.php @@ -0,0 +1,4 @@ +".date("Y-m-d H:i:s") ."

"; +phpinfo(); \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 000000000..ae53a5380 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,87 @@ +# версия синтаксиса +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 + ports: + - '${INTERFACE}:11211:11211' + networks: + - app-network + stdin_open: true + tty: true + restart: unless-stopped + + redis: + image: redis:latest + container_name: myapp/redis + ports: + - "6379:6379" + 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 \ No newline at end of file diff --git a/fpm/Dockerfile b/fpm/Dockerfile new file mode 100644 index 000000000..d65939696 --- /dev/null +++ b/fpm/Dockerfile @@ -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"] diff --git a/fpm/php.ini b/fpm/php.ini new file mode 100644 index 000000000..58ae75084 --- /dev/null +++ b/fpm/php.ini @@ -0,0 +1,2 @@ +session.save_handler = memcache +session.save_path = "tcp://memcache:11211" \ No newline at end of file diff --git a/mysql/Dockerfile b/mysql/Dockerfile new file mode 100644 index 000000000..1c94c727e --- /dev/null +++ b/mysql/Dockerfile @@ -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 diff --git a/mysql/my.cnf b/mysql/my.cnf new file mode 100644 index 000000000..8b29f51b9 --- /dev/null +++ b/mysql/my.cnf @@ -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="" + diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 000000000..41e66977f --- /dev/null +++ b/nginx/Dockerfile @@ -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;"] \ No newline at end of file diff --git a/nginx/hosts/mysite.local.conf b/nginx/hosts/mysite.local.conf new file mode 100644 index 000000000..0bde61ad5 --- /dev/null +++ b/nginx/hosts/mysite.local.conf @@ -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; + } +} From 0deb743439258b5658d05faeee534e05c6456ba9 Mon Sep 17 00:00:00 2001 From: Modesov Denis Date: Mon, 18 Nov 2024 13:06:22 +0400 Subject: [PATCH 02/11] hw1 fix --- code/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/index.php b/code/index.php index bcf0cea25..d1e3be6bf 100644 --- a/code/index.php +++ b/code/index.php @@ -1,4 +1,4 @@ ".date("Y-m-d H:i:s") ."

"; -phpinfo(); \ No newline at end of file +echo "Привет!
" . date("Y-m-d H:i:s") . "

"; +phpinfo(); From 9983096296e3ac3cd85b76623333a836c64c3e3a Mon Sep 17 00:00:00 2001 From: Modesov Denis Date: Mon, 18 Nov 2024 13:09:48 +0400 Subject: [PATCH 03/11] hw1 fix --- code/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/code/index.php b/code/index.php index d1e3be6bf..24b238ca4 100644 --- a/code/index.php +++ b/code/index.php @@ -1,4 +1,3 @@ " . date("Y-m-d H:i:s") . "

"; phpinfo(); From a4acd7b439c1fa37695b9ce01b69d67aca95d50f Mon Sep 17 00:00:00 2001 From: Modesov Denis Date: Mon, 18 Nov 2024 13:11:46 +0400 Subject: [PATCH 04/11] hw1 fix --- code/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/index.php b/code/index.php index 24b238ca4..d9e5f56c3 100644 --- a/code/index.php +++ b/code/index.php @@ -1,3 +1,3 @@ " . date("Y-m-d H:i:s") . "

"; + phpinfo(); From aef0ec79bbba0f5f90c476b4e3c026faea306c59 Mon Sep 17 00:00:00 2001 From: Modesov Denis Date: Mon, 18 Nov 2024 13:14:15 +0400 Subject: [PATCH 05/11] hw1 fix --- code/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/index.php b/code/index.php index d9e5f56c3..7807d6778 100644 --- a/code/index.php +++ b/code/index.php @@ -1,3 +1,3 @@ Date: Mon, 18 Nov 2024 13:17:32 +0400 Subject: [PATCH 06/11] hw1 fix --- code/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/index.php b/code/index.php index 7807d6778..d9e5f56c3 100644 --- a/code/index.php +++ b/code/index.php @@ -1,3 +1,3 @@ Date: Mon, 18 Nov 2024 13:24:30 +0400 Subject: [PATCH 07/11] hw1 fix --- code/index.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/index.php b/code/index.php index d9e5f56c3..fca9292e7 100644 --- a/code/index.php +++ b/code/index.php @@ -1,3 +1,5 @@ Date: Mon, 18 Nov 2024 13:27:47 +0400 Subject: [PATCH 08/11] hw1 fix --- code/index.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/index.php b/code/index.php index fca9292e7..8b7d892e9 100644 --- a/code/index.php +++ b/code/index.php @@ -1,5 +1,4 @@
"; phpinfo(); From f11d65d63e02323486406480ff6b7d391933db96 Mon Sep 17 00:00:00 2001 From: Modesov Denis Date: Mon, 18 Nov 2024 13:38:57 +0400 Subject: [PATCH 09/11] hw1 fix --- code/index.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/index.php b/code/index.php index 8b7d892e9..4e899cfc9 100644 --- a/code/index.php +++ b/code/index.php @@ -1,4 +1,4 @@ -
"; -phpinfo(); + Date: Mon, 18 Nov 2024 13:40:34 +0400 Subject: [PATCH 10/11] hw1 fix --- code/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/code/index.php b/code/index.php index 4e899cfc9..83f154933 100644 --- a/code/index.php +++ b/code/index.php @@ -1,4 +1,3 @@ Date: Wed, 20 Nov 2024 10:19:26 +0400 Subject: [PATCH 11/11] h1 delete ports in redis and memcached --- docker-compose.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index ae53a5380..bff7f0662 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -37,8 +37,6 @@ services: container_name: myapp/memcached volumes: - ./cache:/var/lib/memcached - ports: - - '${INTERFACE}:11211:11211' networks: - app-network stdin_open: true @@ -48,8 +46,6 @@ services: redis: image: redis:latest container_name: myapp/redis - ports: - - "6379:6379" volumes: - ./redis:/var/lib/redis environment: