From 5f0a1cc638a873d5933bac07bae08f4095f23fe4 Mon Sep 17 00:00:00 2001 From: maurelio Date: Sun, 17 Mar 2024 18:14:22 +0000 Subject: [PATCH] [FTR] - Rodando projeto em docker --- Dockerfile | 40 +++++++++++++++++++++++++++++++++ docker-compose.yaml | 55 +++++++++++++++++++++++++++++++++++++++++++++ nginx/nginx.conf | 25 +++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml create mode 100644 nginx/nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bad7cd2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +FROM php:7.1-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 \ + nodejs \ + npm + +# 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:2.2 /usr/bin/composer /usr/bin/composer + +# RUN /bin/bash -c composer install + +RUN rm /bin/sh && ln -s /bin/bash /bin/sh + +# 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 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..f58456f --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,55 @@ + + +version: "0.1" +services: + app: + build: + args: + user: sira + uid: 1000 + context: ./ + dockerfile: Dockerfile + image: sira + container_name: sira-app + restart: unless-stopped + working_dir: /var/www/ + ports: + - 8001:8001 + volumes: + - ./:/var/www + networks: + - sira + + db: + image: mysql:8.3.0 + container_name: sira-db + restart: unless-stopped + ports: + - 3306:3306 + environment: + MYSQL_DATABASE: ${DB_DATABASE} + MYSQL_ROOT_PASSWORD: 1234 + MYSQL_PASSWORD: ${DB_PASSWORD} + MYSQL_USER: ${DB_USERNAME} + SERVICE_TAGS: dev + SERVICE_NAME: mysql + networks: + - sira + + nginx: + image: nginx:latest + container_name: sira-nginx + restart: unless-stopped + ports: + - 8000:80 + volumes: + - ./:/var/www + - ./nginx:/etc/nginx/conf.d + networks: + - sira + +networks: + sira: + driver: bridge + + diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..6452a34 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 80; + root /var/www/public; + + index index.php index.html; + + + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; + + 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; + } +}