Last active
July 16, 2024 17:34
-
-
Save tayyebi/5cf833e07112539d600ae0b3f75a22a8 to your computer and use it in GitHub Desktop.
Laravel 11.0 Dockerize
This file contains hidden or 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
version: '3.8' | |
services: | |
npm: | |
container_name: npm | |
image: node:latest | |
volumes: | |
- ./:/var/www/html | |
working_dir: /var/www/html | |
command: bash -c "npm install && npm install && npm run build" | |
cb: | |
image: codebase:latest | |
container_name: cb | |
hostname: cb | |
build: | |
target: cb | |
context: . | |
env_file: | |
- .env | |
ports: | |
- "80:80" | |
volumes: | |
- .:/var/www/html | |
# entrypoint: ./startup.sh | |
networks: | |
- app | |
depends_on: | |
- db | |
db: | |
platform: "linux/amd64" | |
image: mariadb | |
container_name: db | |
hostname: db | |
env_file: | |
- .env | |
environment: | |
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} | |
MYSQL_DATABASE: ${DB_DATABASE} | |
MYSQL_USER: ${DB_USERNAME} | |
MYSQL_PASSWORD: ${DB_PASSWORD} | |
volumes: | |
- ../db:/var/lib/mysql | |
networks: | |
- app | |
networks: | |
app: | |
external: true |
This file contains hidden or 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
# Use PHP with Apache as the base image | |
# Note: `cb` stands for 'code-base' | |
FROM php:8.2-apache as cb | |
# Install Additional System Dependencies | |
RUN apt-get update && apt-get install -y \ | |
libzip-dev \ | |
zip | |
# Clear cache | |
RUN apt-get clean && rm -rf /var/lib/apt/lists/* | |
# Enable Apache mod_rewrite for URL rewriting | |
RUN a2enmod rewrite | |
# Install PHP extensions | |
RUN docker-php-ext-install pdo_mysql zip | |
# Install composer | |
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | |
# Configure Apache DocumentRoot to point to Laravel's public directory | |
# and update Apache configuration files | |
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public | |
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf | |
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf | |
# Set the working directory | |
WORKDIR /var/www/html | |
# Keep container running | |
CMD ["bash", "/usr/sbin/apache2ctl", "-D", "FOREGROUND"] |
This file contains hidden or 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
# Install project dependencies | |
composer install | |
# Set permissions | |
chown -R www-data:www-data /var/www/html/public /var/www/html/storage /var/www/html/bootstrap/cache | |
# Run artisan commands | |
php artisan migrate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment