Skip to content

Commit a97022b

Browse files
Docker Compose PHP e Nginx
0 parents  commit a97022b

File tree

8 files changed

+211
-0
lines changed

8 files changed

+211
-0
lines changed

.env

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
web_container_name=nginx_server
2+
web_container_restar=unless-stopped
3+
web_container_host_insecure=80
4+
web_container_host_volume=./
5+
web_container_host_conf_volume=./etc/nginx/
6+
7+
php_container_name=php-fpm_server
8+
php_container_restar=unless-stopped
9+
php_container_host_volume=./
10+
php_container_host_conf_volume=./etc/php/php.ini

Dockerfile

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
FROM nginx:alpine as nginx_target
2+
3+
# FROM php:7.4-fpm as php_target
4+
FROM php:8.2-fpm-bullseye as php_target
5+
6+
# -----------------------------------------------------------------------
7+
# Configurações abaixo foram retiradas de: https://github.com/fabriciopolito/docker-compose-lamp
8+
# -----------------------------------------------------------------------
9+
10+
ARG DEBIAN_FRONTEND=noninteractive
11+
12+
# Update
13+
RUN apt-get -y update --fix-missing && \
14+
apt-get upgrade -y && \
15+
apt-get --no-install-recommends install -y apt-utils && \
16+
rm -rf /var/lib/apt/lists/*
17+
18+
# Install useful tools and install important libaries
19+
RUN apt-get -y update && \
20+
apt-get -y --no-install-recommends install nano wget \
21+
dialog \
22+
libsqlite3-dev \
23+
libsqlite3-0 && \
24+
apt-get -y --no-install-recommends install default-mysql-client \
25+
zlib1g-dev \
26+
libzip-dev \
27+
libicu-dev && \
28+
apt-get -y --no-install-recommends install --fix-missing apt-utils \
29+
build-essential \
30+
git \
31+
curl \
32+
libonig-dev && \
33+
apt-get install -y iputils-ping && \
34+
apt-get -y --no-install-recommends install --fix-missing libcurl4 \
35+
libcurl4-openssl-dev \
36+
zip \
37+
openssl && \
38+
rm -rf /var/lib/apt/lists/* && \
39+
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
40+
41+
RUN pecl install xdebug-3.2.1 && \
42+
docker-php-ext-enable xdebug && \
43+
mkdir -p /var/log/xdebug
44+
45+
# Other PHP8 Extensions
46+
RUN docker-php-ext-install pdo_mysql && \
47+
docker-php-ext-install pdo_sqlite && \
48+
docker-php-ext-install bcmath && \
49+
docker-php-ext-install mysqli && \
50+
docker-php-ext-install curl && \
51+
docker-php-ext-install zip && \
52+
docker-php-ext-install -j$(nproc) intl && \
53+
docker-php-ext-install mbstring && \
54+
docker-php-ext-install gettext && \
55+
docker-php-ext-install calendar && \
56+
docker-php-ext-install exif

README.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
# Docker Compose PHP e Nginx
3+
4+
## Esta stack consiste nos seguintes pacotes e configurações:
5+
6+
- **Nginx**
7+
- **PHP-FPM** 7 ou 8 (incluindo Git, curl, Xdebug e Composer)
8+
9+
### Instalação
10+
11+
- Clonar este repositório.
12+
- Caso desejado, alterar o arquivo de configurações no `./.env`
13+
- Caso desejado, alterar os arquivos de configurações em `./etc/`
14+
- Coloque seus arquivos fonte em `./public/`
15+
- Por fim, execute: `docker compose up -d`
16+
17+
### Listando os containers em execução
18+
19+
- `docker container ls`
20+
21+
### Parando um container específico
22+
23+
- `docker container stop <nome_ou_id>`
24+
25+
### Reiniciado um container específico
26+
27+
- `docker container restart <nome_ou_id>`
28+
29+
### Derrubando todos os container desta stack
30+
31+
- `docker compose down`
32+
33+
### Acessando o terminal do Nginx
34+
35+
- `docker container exec -it nginx_server sh` ou `docker container exec -it <nome_do_servico_no_docker_compose-ou-id> sh`
36+
37+
Teste de comunicação entre os dois container, no terminal do Nginx:
38+
- `ping php_service`
39+
40+
### Acessando o terminal do PHP
41+
42+
- `docker container exec -it php-fpm_server bash` ou `docker container exec -it <nome_do_servico_no_docker_compose-ou-id> bash`
43+
44+
Teste de comunicação entre os dois container, no terminal do PHP:
45+
46+
- `ping nginx_server`
47+
48+
### Inspecionando os contêineres
49+
50+
- `docker container inspect nginx_server`
51+
- `docker container inspect php-fpm_server`
52+
53+
### Ver o consumo dos recursos
54+
55+
- `docker container stats`
56+
57+
- `ctrl + c` para sair.
58+
59+
### Limpando os caches do Docker
60+
61+
- Visualizando espaço utilizado pelo Docker: `docker system df`
62+
- Removendo contêineres do cache: `docker container prune -f`
63+
- Removendo imagens do cache não vinculado a contêineres: `docker image prune -f`
64+
- Removendo volumes anônimos: `docker volume prune -f`
65+
- Removendo cache de compilação: `docker buildx prune -f`
66+
- Removendo rede não utilizadas: `docker network prune -f`
67+
- **Removendo tudo**: `docker system prune --volumes -af`
68+
69+
### Personalização
70+
71+
Você é livre para adicionar quaisquer outras imagens a esta stack, como:
72+
73+
- Banco de Dados (por exemplo, MySQL, PostgreSQL, Redis)
74+
- phpMyAdmin
75+
- Mensageria (por exemplo, RabbitMQ, Kafka)
76+
77+
Basta incluir as configurações correspondentes no arquivo `docker-compose.yml`.

docker-compose.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
services:
2+
web_service:
3+
container_name: ${web_container_name-nginx_default}
4+
restart: ${web_container_restar-'unless-stopped'}
5+
build:
6+
context: .
7+
target: nginx_target
8+
ports:
9+
- ${web_container_host_insecure-80}:80
10+
volumes:
11+
- ${web_container_host_conf_volume-./etc/nginx/}:/etc/nginx/conf.d/
12+
- ${web_container_host_volume-./}:/var/www
13+
networks:
14+
- docker-lamp-nginx-php
15+
16+
php_service:
17+
container_name: ${php_container_name-php_default}
18+
restart: ${php_container_restar-'unless-stopped'}
19+
build:
20+
context: .
21+
target: php_target
22+
volumes:
23+
- ${php_container_host_volume-./}:/var/www
24+
- ${php_container_host_conf_volume-./etc/php/php.ini}:/usr/local/etc/php/php.ini
25+
networks:
26+
- docker-lamp-nginx-php
27+
28+
networks:
29+
docker-lamp-nginx-php:
30+
driver: bridge
31+
32+

etc/nginx/default.conf

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
server {
2+
listen 80;
3+
index index.php index.html;
4+
root /var/www/public;
5+
6+
location ~ \.php$ {
7+
try_files $uri =404;
8+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
9+
fastcgi_pass php_service:9000;
10+
fastcgi_index index.php;
11+
include fastcgi_params;
12+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
13+
fastcgi_param PATH_INFO $fastcgi_path_info;
14+
}
15+
16+
location / {
17+
try_files $uri $uri/ /index.php?$query_string;
18+
gzip_static on;
19+
}
20+
21+
error_log /var/log/nginx/error.log;
22+
access_log /var/log/nginx/access.log;
23+
}

etc/php/php.ini

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
memory_limit = 256M
2+
post_max_size = 50M
3+
upload_max_filesize = 50M
4+
5+
xdebug.mode=debug
6+
xdebug.start_with_request=yes
7+
xdebug.client_host=host.docker.internal
8+
xdebug.discover_client_host=1

public/index.php

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
echo $_SERVER['SCRIPT_FILENAME'] . "<br>";
3+
echo "PHP: " . PHP_VERSION . "<br>";

public/info.php

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
phpinfo();

0 commit comments

Comments
 (0)