Browse Source

Basic php application docker setup

Herton 4 years ago
commit
19ff20a094
6 changed files with 110 additions and 0 deletions
  1. 3 0
      .gitignore
  2. 34 0
      Dockerfile
  3. 46 0
      docker-compose.yml
  4. 20 0
      docker/nginx/default.conf
  5. 1 0
      public/index.php
  6. 6 0
      readme.md

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.env
+/vendor
+/node_modules

+ 34 - 0
Dockerfile

@@ -0,0 +1,34 @@
+FROM php:7.4-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

+ 46 - 0
docker-compose.yml

@@ -0,0 +1,46 @@
+version: "3.7"
+services:
+  app:
+    build:
+      args:
+        user: art
+        uid: 1000
+      context: ./
+      dockerfile: Dockerfile
+    container_name: lara-app
+    restart: unless-stopped
+    working_dir: /var/www/
+    volumes:
+      - ./:/var/www
+    networks:
+      - web
+
+  db:
+    image: mysql:5.7
+    container_name: lara-db
+    restart: unless-stopped
+    environment:
+      MYSQL_DATABASE: ${DB_DATABASE}
+      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
+      MYSQL_PASSWORD: ${DB_PASSWORD}
+      MYSQL_USER: ${DB_USERNAME}
+    ports:
+      - 23306:3306
+    networks:
+      - web
+
+  server:
+    image: nginx:1.17-alpine
+    container_name: lara-nginx
+    restart: unless-stopped
+    ports:
+      - 280:80
+    volumes:
+      - ./:/var/www
+      - ./docker/nginx:/etc/nginx/conf.d
+    networks:
+      - web
+
+networks:
+  web:
+    driver: bridge

+ 20 - 0
docker/nginx/default.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;
+    }
+}

+ 1 - 0
public/index.php

@@ -0,0 +1 @@
+<?= 'Sup?';

+ 6 - 0
readme.md

@@ -0,0 +1,6 @@
+### Basic App Docker Setup
+PHP, MySQL and Nginx application bootstrap.
+
+### To run the example:
+1. Pull the repository locally
+2. Run `docker-compose up -d`