-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up docker and now using nginx
- Loading branch information
1 parent
aedf720
commit 0fe9c48
Showing
6 changed files
with
101 additions
and
2,074 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
server { | ||
listen 80; | ||
server_name localhost; | ||
|
||
root /var/www/html/public; | ||
index index.php index.html; | ||
|
||
location / { | ||
try_files $uri $uri/ /index.php?$query_string; | ||
} | ||
|
||
location ~ \.php$ { | ||
include fastcgi_params; | ||
fastcgi_pass app:9000; # This matches the PHP-FPM service in docker-compose | ||
fastcgi_index index.php; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
} | ||
|
||
location ~ /\.ht { | ||
deny all; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,35 @@ | ||
# Use a specific version of composer to ensure reproducibility | ||
FROM composer:2.2 as builder | ||
# Use the official PHP image with FPM (FastCGI Process Manager) | ||
FROM php:8.3-fpm | ||
|
||
WORKDIR /app | ||
# Install necessary PHP extensions | ||
RUN docker-php-ext-install mysqli pdo pdo_mysql | ||
|
||
# Copy local packages for composer | ||
COPY ./packages/ ./packages/ | ||
# Install Git we'll need it for Composer | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends git | ||
|
||
# Copying only the composer files first to leverage Docker cache | ||
COPY composer.json composer.lock ./ | ||
# Install Composer | ||
COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer | ||
|
||
# Install composer dependencies, skipping scripts to speed up build and avoid potential security risks | ||
RUN composer install --ignore-platform-reqs --no-scripts --no-progress --no-ansi --no-dev | ||
|
||
# Copy the rest of the application code | ||
COPY . . | ||
|
||
# Use a specific version of the PHP image for consistency | ||
FROM php:8.3-apache | ||
|
||
# Combine RUN commands to reduce the number of layers and overall size | ||
RUN docker-php-ext-install mysqli pdo pdo_mysql && \ | ||
docker-php-ext-enable mysqli pdo pdo_mysql && \ | ||
a2enmod rewrite | ||
|
||
# Consider adding any required custom PHP configuration | ||
# COPY ./docker/php/php.ini /usr/local/etc/php/ | ||
# Set the working directory in the container | ||
WORKDIR /var/www/html | ||
|
||
# Apache configuration | ||
COPY ./docker/apache/000-default.conf /etc/apache2/sites-enabled/000-default.conf | ||
# Copy the application code to the working directory | ||
COPY . /var/www/html | ||
|
||
# Copy the application code with installed dependencies | ||
COPY --from=builder /app /var/www/html | ||
# Install Composer dependencies with optimized options for production | ||
RUN composer install \ | ||
--ignore-platform-reqs \ | ||
--no-scripts \ | ||
--no-progress \ | ||
--no-ansi \ | ||
--no-dev | ||
|
||
# Correct ownership to the Apache user and group | ||
# This may vary depending on your base image; www-data is typical for Apache on Debian-based images | ||
# Set proper permissions for the web server | ||
RUN chown -R www-data:www-data /var/www/html | ||
|
||
# Optionally, specify a custom entrypoint or CMD if your application requires initialization scripts | ||
|
||
WORKDIR /var/www/html | ||
|
||
# Expose port 80 is optional since the base image already exposes it | ||
# EXPOSE 80 | ||
# Expose port 9000 for PHP-FPM | ||
EXPOSE 9000 | ||
|
||
# The base PHP Apache image uses Apache as the default command, so no need to re-specify CMD unless customizing | ||
# Start PHP-FPM | ||
CMD ["php-fpm"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,75 @@ | ||
version: "3.8" | ||
version: '3.8' # Specify the version of the Docker Compose file format | ||
|
||
services: | ||
# Nginx Web Server | ||
web: | ||
container_name: nginx_web | ||
image: nginx:latest # Use the latest official Nginx image | ||
ports: | ||
- "80:80" # Map port 80 on the host to port 80 in the container | ||
volumes: | ||
- ./src:/var/www/html # Mount the 'src' directory to the web root inside the container | ||
- ./Docker/nginx.conf:/etc/nginx/conf.d/default.conf # Use a custom Nginx configuration | ||
depends_on: | ||
- app # Ensure PHP-FPM service is started before Nginx | ||
networks: | ||
- app_network | ||
|
||
# PHP-FPM Service | ||
app: | ||
container_name: app | ||
container_name: php_fpm_app | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
context: . # Use the current directory to build the Dockerfile | ||
dockerfile: Dockerfile # Specify the Dockerfile | ||
volumes: | ||
- ./:/var/www/html | ||
- ./docker/php/php.ini:/usr/local/etc/php/conf.d/local.ini | ||
networks: | ||
- app | ||
ports: | ||
- "80:80" | ||
- ./src:/var/www/html # Mount the 'src' directory to the web root inside the container | ||
depends_on: | ||
- composer | ||
- mysql | ||
- composer # Ensure Composer runs before starting the app service | ||
- mysql # Ensure MySQL is started before the app service | ||
networks: | ||
- app_network | ||
|
||
# Composer service for managing PHP dependencies | ||
composer: | ||
container_name: composer | ||
image: composer:2.2 | ||
working_dir: /var/www/html | ||
container_name: composer_service | ||
image: composer:2.2 # Use the official Composer image, version 2.2 | ||
working_dir: /var/www/html # Set the working directory inside the container | ||
volumes: | ||
- ./:/var/www/html | ||
entrypoint: ["composer", "--ignore-platform-reqs", "--no-progress", "--no-ansi"] | ||
command: ["install"] | ||
- ./src:/var/www/html # Mount the 'src' directory to the working directory in the container | ||
entrypoint: # Override the entrypoint to run Composer commands with specified options | ||
- composer | ||
- "--ignore-platform-reqs" # Ignore platform requirements during installation | ||
- "--no-progress" # Disable progress display for cleaner output | ||
- "--no-ansi" # Disable ANSI colors in the output | ||
command: ["install"] # Install PHP dependencies defined in composer.json | ||
|
||
# MySQL service for database interactions | ||
mysql: | ||
container_name: db | ||
image: mysql:8.3 | ||
container_name: mysql_db | ||
image: mysql:8.3 # Use MySQL version 8.3 | ||
ports: | ||
- '${FORWARD_DB_PORT:-3306}:3306' | ||
- '${DB_PORT:-3306}:3306' # Dynamically set the port with an optional environment variable | ||
environment: | ||
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}' | ||
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}' # Use environment variables for sensitive data | ||
MYSQL_ROOT_HOST: "%" | ||
MYSQL_DATABASE: '${DB_DATABASE}' | ||
MYSQL_USER: '${DB_USERNAME}' | ||
MYSQL_PASSWORD: '${DB_PASSWORD}' | ||
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' | ||
MYSQL_DATABASE: '${DB_DATABASE}' # Set the database name from the environment | ||
MYSQL_USER: '${DB_USERNAME}' # Set the database user from the environment | ||
MYSQL_PASSWORD: '${DB_PASSWORD}' # Set the database password from the environment | ||
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' # Optionally allow empty passwords | ||
volumes: | ||
- mysql:/var/lib/mysql | ||
- mysql_data:/var/lib/mysql # Store MySQL data in a named volume | ||
networks: | ||
- app | ||
- app_network | ||
healthcheck: | ||
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"] | ||
interval: 10s | ||
retries: 3 | ||
timeout: 5s | ||
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"] # Check if MySQL is available | ||
interval: 10s # Check every 10 seconds | ||
retries: 3 # Retry 3 times before marking as unhealthy | ||
timeout: 5s # Timeout after 5 seconds | ||
|
||
networks: | ||
app: | ||
driver: bridge | ||
app_network: | ||
driver: bridge # Use the default bridge network driver | ||
|
||
volumes: | ||
mysql: | ||
driver: local | ||
mysql_data: | ||
driver: local # Use local storage for MySQL data |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.