Skip to content

Instantly share code, notes, and snippets.

@danielpereirabp
Last active March 11, 2023 22:18
Show Gist options
  • Save danielpereirabp/5ab18bbcd85c3bb190b14aadd9ad359e to your computer and use it in GitHub Desktop.
Save danielpereirabp/5ab18bbcd85c3bb190b14aadd9ad359e to your computer and use it in GitHub Desktop.
Docker
# USER=$USER UID=$UID docker-compose up -d --build
version: "3.7"
services:
app:
build:
args:
user: ${USER}
uid: ${UID}
context: ./
dockerfile: .docker/Dockerfile
image: my-docker-application
container_name: my-docker-application-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- my-docker-application
db:
image: mariadb:10.2
container_name: my-docker-application-db
restart: unless-stopped
ports:
- 3306:3306
environment:
MYSQL_DATABASE: my-docker-application
MYSQL_ROOT_PASSWORD:
MYSQL_PASSWORD:
MYSQL_USER: my-db-user
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql
networks:
- my-docker-application
nginx:
image: nginx:alpine
container_name: my-docker-application-nginx
restart: unless-stopped
ports:
- 80:80
volumes:
- ./:/var/www
- ./.docker/nginx:/etc/nginx/conf.d/
networks:
- my-docker-application
redis:
image: redis:5.0
container_name: my-docker-application-redis
ports:
- 6379:6379
networks:
- my-docker-application
mailhog:
image: mailhog/mailhog
container_name: my-docker-application-mailhog
ports:
- 1025:1025
- 8025:8025
networks:
- my-docker-application
volumes:
dbdata:
driver: local
networks:
my-docker-application:
driver: bridge
FROM php:8.0-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
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;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment