diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..59d5f44 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +services: + # The Application Service (PHP) + app: + build: + context: ./server + dockerfile: Dockerfile + args: + - user=${USER} + - uid=${UID} + image: casadoc-app + container_name: casadoc-app + restart: unless-stopped + tty: true + environment: + SERVICE_NAME: app + SERVICE_TAGS: dev + working_dir: /var/www + volumes: + - ./server:/var/www + - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini + networks: + - app-network + + # The Web Server (Nginx) + webserver: + image: nginx:alpine + container_name: casadoc-webserver + restart: unless-stopped + tty: true + ports: + - "8000:80" + volumes: + - ./server:/var/www + - ./docker/nginx/conf.d/:/etc/nginx/conf.d/ + networks: + - app-network + +# Docker Networks +networks: + app-network: + driver: bridge diff --git a/docker/nginx/conf.d/app.conf b/docker/nginx/conf.d/app.conf new file mode 100644 index 0000000..f397fbd --- /dev/null +++ b/docker/nginx/conf.d/app.conf @@ -0,0 +1,20 @@ +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; + } +} diff --git a/docker/php/local.ini b/docker/php/local.ini new file mode 100644 index 0000000..afffefa --- /dev/null +++ b/docker/php/local.ini @@ -0,0 +1,2 @@ +upload_max_filesize=100M +post_max_size=100M diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..e729b4c --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,35 @@ +FROM php:8.2-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 + +# Switch back to the application user +USER $user