Skip to content

Instantly share code, notes, and snippets.

@DanRibbens
Created May 25, 2020 18:06
Show Gist options
  • Select an option

  • Save DanRibbens/f99147436b6f3ed270cd27a30519effc to your computer and use it in GitHub Desktop.

Select an option

Save DanRibbens/f99147436b6f3ed270cd27a30519effc to your computer and use it in GitHub Desktop.

Revisions

  1. DanRibbens created this gist May 25, 2020.
    51 changes: 51 additions & 0 deletions .docker\Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    FROM php:7.4-fpm

    # Copy composer.lock and composer.json
    COPY ../composer.lock composer.json /var/www/

    # Set working directory
    WORKDIR /var/www

    # Install dependencies
    RUN apt-get update && apt-get install -y \
    build-essential \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl \
    libpq-dev \
    libzip-dev

    # Clear cache
    RUN apt-get clean && rm -rf /var/lib/apt/lists/*

    # Install extensions
    RUN docker-php-ext-install pdo_pgsql zip exif pcntl
    RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
    RUN docker-php-ext-install gd

    # Install composer
    RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

    # Add user for laravel application
    RUN groupadd -g 1000 www
    RUN useradd -u 1000 -ms /bin/bash -g www www

    # Copy existing application directory contents
    COPY php /var/www

    # Copy existing application directory permissions
    COPY --chown=www:www php /var/www

    # Change current user to www
    USER www

    # Expose port 9000 and start php-fpm server
    EXPOSE 9000
    CMD ["php-fpm"]
    36 changes: 36 additions & 0 deletions .docker\nginx\conf.d\app.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    server {
    listen 80;
    root /var/www/public;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    index index.php index.html;
    charset utf-8;
    location / {
    try_files $uri $uri/ /index.php?$query_string;
    gzip_static on;
    }
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt { access_log off; log_not_found off; }
    error_page 404 /index.php;
    location ~ \.php$ {
    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;

    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    }
    location ~ /\.(?!well-known).* {
    deny all;
    }
    }
    2 changes: 2 additions & 0 deletions .docker\php\local.ini
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    upload_max_filesize=10M
    post_max_size=10M
    6 changes: 6 additions & 0 deletions .dockerignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    .git/
    vendor/
    node_modules/
    public/js/
    public/css/
    yarn-error.log
    62 changes: 62 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    version: '3'
    services:

    #PHP Service
    app:
    build:
    context: .
    dockerfile: ./.docker/Dockerfile
    image: digitalocean.com/php
    container_name: ${APP_NAME}-app
    restart: unless-stopped
    tty: true
    environment:
    SERVICE_NAME: app
    SERVICE_TAGS: dev
    working_dir: /var/www
    volumes:
    - ./:/var/www
    - ./.docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
    - app-network

    #Nginx Service
    webserver:
    image: nginx:alpine
    container_name: ${APP_NAME}-webserver
    restart: unless-stopped
    tty: true
    ports:
    - "8000:80"
    - "443:443"
    volumes:
    - ./:/var/www
    - ./.docker/nginx/conf.d/:/etc/nginx/conf.d/
    networks:
    - app-network

    #PostgreSQL Service
    db:
    image: postgres:alpine
    container_name: ${APP_NAME}-db
    restart: unless-stopped
    tty: true
    ports:
    - "5432:5432"
    environment:
    POSTGRES_USER: ${DB_USERNAME}
    POSTGRES_PASSWORD: ${DB_PASSWORD}
    SERVICE_TAGS: ${APP_ENV}
    SERVICE_NAME: postgres
    volumes:
    - dbdata:/var/lib/postgres
    networks:
    - app-network

    #Docker Networks
    networks:
    app-network:
    driver: bridge
    volumes:
    dbdata:
    driver: local
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # docker-compose & dockerfile for PHP 7.4, Nginx, PostgreSQL