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

Добавил Docker. Сделал связь между PHP-FPM и Nginx через Unix-Socket.… #71

Open
wants to merge 3 commits into
base: BeliaevNO/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POSTGRES_USER=root
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Закомичен .env. Его надо удалить и добавить в .gitignore

POSTGRES_PASSWORD=root
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MYSQL_DATABASE=laravel
MYSQL_ROOT_PASSWORD=your_mysql_root_password
4 changes: 4 additions & 0 deletions Docker/code/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

Check failure on line 1 in Docker/code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line
echo "Hello, Проверяющие :)";

phpinfo();

Check failure on line 4 in Docker/code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 newline at end of file; 0 found
27 changes: 27 additions & 0 deletions Docker/fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM php:8.3-fpm

RUN apt-get update && apt-get install -y \
curl \
wget \
git \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libonig-dev \
libzip-dev \
&& docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& mkdir -p /run/php

# Устанавливаем Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
COPY php.ini /usr/local/etc/php/conf.d/php-custom.ini
COPY zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf


WORKDIR /data

VOLUME /data

CMD ["php-fpm"]
2 changes: 2 additions & 0 deletions Docker/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"
6 changes: 6 additions & 0 deletions Docker/fpm/zz-docker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[global]
daemonize = no

[www]
listen = /run/php/php-fpm.sock
listen.mode = 0666
7 changes: 7 additions & 0 deletions Docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM nginx:latest
COPY hosts/application.local.conf /etc/nginx/conf.d/application.local.conf

WORKDIR /data
VOLUME /data
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
26 changes: 26 additions & 0 deletions Docker/nginx/hosts/application.local.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
server {
listen 80;
server_name application.local;

root /data/application.local;

index index.php index.html;

location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~* .php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
4 changes: 4 additions & 0 deletions code/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

Check failure on line 1 in code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line
echo "Hello, Otus!";

phpinfo();

Check failure on line 4 in code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 newline at end of file; 0 found
65 changes: 65 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

version: '3'

services:
app:
build:
context: Docker/fpm
dockerfile: Dockerfile
image: myapp/php
container_name: app
volumes:
- ./Docker/code:/data/application.local
- "phpsocket:/var/run"
networks:
- app-network

webserver:
build:
context: Docker/nginx
dockerfile: Dockerfile
image: myapp/nginx
container_name: webserver
ports:
- "8080:80"
- "443:443"
volumes:
- ./Docker/code:/data/application.local
- "phpsocket:/var/run"
networks:
- app-network

memcached:
image: memcached:latest
ports:
- "11211:11211"
networks:
- app-network

redis:
image: redis:latest
ports:
- "6379:6379"
networks:
- app-network

postgres_db:
image: postgres:latest
container_name: db
restart: always
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ports:
- '5432:5432'
volumes:
- postgres_db:/var/lib/postgresql/data


volumes:
postgres_db:
driver: local
phpsocket:
networks:
app-network:
driver: bridge
54 changes: 54 additions & 0 deletions docker-compose.yml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# версия синтаксиса
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот только что проверял человека у которого был практически идентичные файлы.

version: '3'

# в этом блоке мы описываем контейнеры, которые будут запускаться
services:

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

#контейне с Nginx
webserver:
build:
context: ./nginx
dockerfile: Dockerfile
image: myapp/nginx
container_name: webserver
volumes:
- ./code:/data/mysite.local
# проброс портов
ports:
- "80:80"
- "443:443"
networks:
- app-network

#MySQL Service
db:
image: mysql:5.7.22
container_name: db
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
networks:
- app-network
volumes:
- ./dbdata:/var/lib/mysql

#Docker Networks
networks:
app-network:
driver: bridge
Loading