Skip to content

Instantly share code, notes, and snippets.

@viniciusmelocodes
Forked from DanRibbens/.docker\Dockerfile
Created July 26, 2023 13:55
Show Gist options
  • Save viniciusmelocodes/d19bec161e4b6bf858ee7469e448505c to your computer and use it in GitHub Desktop.
Save viniciusmelocodes/d19bec161e4b6bf858ee7469e448505c to your computer and use it in GitHub Desktop.
docker-compose & dockerfile for PHP 7.4, Nginx, PostgreSQL
FROM php:7.4-fpm
# Copy composer.lock and composer.json
COPY ../composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
libpq-dev \
libzip-dev
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_pgsql zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY php /var/www
# Copy existing application directory permissions
COPY --chown=www:www php /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
server {
listen 80;
root /var/www/public;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
upload_max_filesize=10M
post_max_size=10M
.git/
vendor/
node_modules/
public/js/
public/css/
yarn-error.log

docker-compose & dockerfile for PHP 7.4, Nginx, PostgreSQL

version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: ./.docker/Dockerfile
image: digitalocean.com/php
container_name: ${APP_NAME}-app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./.docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: ${APP_NAME}-webserver
restart: unless-stopped
tty: true
ports:
- "8000:80"
- "443:443"
volumes:
- ./:/var/www
- ./.docker/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#PostgreSQL Service
db:
image: postgres:alpine
container_name: ${APP_NAME}-db
restart: unless-stopped
tty: true
ports:
- "5432:5432"
environment:
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
SERVICE_TAGS: ${APP_ENV}
SERVICE_NAME: postgres
volumes:
- dbdata:/var/lib/postgres
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
volumes:
dbdata:
driver: local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment