2017 © Pedro Peláez
 

package docker-server

Universal docker server, Nginx, PHP-FPM, MySql, Redis

image

matthew-p/docker-server

Universal docker server, Nginx, PHP-FPM, MySql, Redis

  • Thursday, July 26, 2018
  • by hellboymxb@gmail.com
  • Repository
  • 1 Watchers
  • 1 Stars
  • 7 Installations
  • Shell
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Universal docker server

Nginx (1.17.8), PHP (7.4) / Node (13.10), MySql (5.7), Redis (5.0.7), (*1)

Installation

The preferred way to install this extension., (*2)

Either run, (*3)

  • for composer, (*4)

    php composer.phar require --prefer-dist matthew-p/docker-server
    

    or add, (*5)

    "matthew-p/docker-server": "^5.1.0"
    

    to the require section of your composer.json file., (*6)

  • for npm, (*7)

    npm i --save @matthew-p/docker-server@latest
    

    or add, (*8)

    "@matthew-p/docker-server": "^1.1.1"
    

    to the dependencies section of your package.json file., (*9)

After install package:

  1. Add or update section scripts in composer.json or package.json:, (*10)

    • for composer.json, (*11)

      {
          "scripts": {
              "server": "vendor/bin/site-start.sh --env-file=docker/.env.local",
              "server-run": "vendor/bin/site-run.sh --env-file=docker/.env.local",
              "server-exec": "vendor/bin/site-exec.sh --env-file=docker/.env.local",
      
              // (optional)
              "server-prod": "vendor/bin/site-aws.sh --env-file=docker/.env.prod",
              // (optional)
              "server-deploy-dev": "vendor/bin/site-deploy.sh --env-file=docker/.env.dev"
          }
      }
      
    • for package.json, (*12)

      {
         "scripts": {
             "server": "docker-server-start --env-file=docker/.env.local",
             "server-run": "docker-server-run --env-file=docker/.env.local",
             "server-exec": "docker-server-exec --env-file=docker/.env.local",
      
             // (optional)
             "server-prod": "docker-server-aws --env-file=docker/.env.prod",
             // (optional)
             "server-deploy-dev": "docker-server-deploy --env-file=docker/.env.dev"
         }
      }
      

    where "docker/.env.local" relative path to your local env config (will be created in next step)., (*13)

  2. Run: composer server init or npm run server init. This will create a docker folder in your project root directory., (*14)

  3. Change root-path in docker/nginx/conf-dynamic.d/sample.conf, (*15)

  4. See supported os and config docker/.env.local according to your operating system, (*16)

  5. Run server: composer server up or npm run server up, (*17)

Supported OS

Environments && Commands

PhpStorm samples

Latest docker images

  • NGINX
    • matthewpatell/universal-docker-nginx:3.7
  • SERVER
    • matthewpatell/universal-docker-server:4.0
    • matthewpatell/universal-docker-server:4.0-dev
    • matthewpatell/universal-docker-server:4.0-jre (with java)
  • PHP-FPM:
    • matthewpatell/universal-docker-server-php-fpm:4.0
  • NODE:
    • node:13.10-alpine

FEATURES

  • Multiple config: vendor/bin/site-start.sh --env-file=docker/.env.dev,docker/.env.local
  • Use environment, extends, overriding between configs, (*18)

    # Simple usage
    SERVICES="$SERVICES -f my.yml"
    
    # Will be recompiled (bad example)
    SERVICES="${SERVICES} -f my.yml"
    
    # Will be recompiled (good example)
    SERVICES="${SERVICES_EXTERNAL} -f my.yml"
    
  • Use all environments in docker-compose files
  • Overriding, extends docker-compose files
  • Run container and execute command: composer server-run server "ls && top"
  • Run command in working container: composer server-exec server "composer install"
  • AWS create/update "Task Definitions"
  • Auto update /etc/hosts file on host machine
  • Auto create nginx proxies on host machine
  • Deploy
  • And etc.

LIFEHACKS

  • Configure hosts file:, (*19)

    1. Check nginx container IP and add to hosts file:, (*20)

      docker inspect sample_nginx
      

      view "IPAddress" and add to:, (*21)

      sudo nano /etc/hosts
      

      _172.18.0.4 sample.io_ (for example)
      save and check it., (*22)

    2. Open browser and check sample.io

    OR see below static network layer, (*23)

  • Add static network layer (only for Linux), (*24)

    1. Change SERVICES variable in your local env (docker/.env.local) to: dotenv SERVICES="$SERVICES -f docker/docker-compose.common.yml -f docker/docker-compose.static-network.yml"
    2. Run: composer server restart and check it.
  • Update package without composer install and depencies, (*25)

    • with composer image:
    docker run --rm --interactive --volume $PWD:/app composer update --ignore-platform-reqs --no-scripts
    
    • with server images:
    docker run --rm --interactive --volume $PWD:/app matthewpatell/universal-docker-server:4.0 bash -c 'cd /app && composer install --no-scripts'
    
    • with server image and additional global packages:
    docker run --rm --interactive --volume $PWD:/app matthewpatell/universal-docker-server:4.0 bash -c 'cd /app && composer global require "fxp/composer-asset-plugin:^1.4.2" && composer global require "hirak/prestissimo:~0.3.7" && composer install --no-scripts'
    
  • Use git-container instead of git itself, (*26)


docker run -it --rm \ --user $(id -u):$(id -g) \ -v $HOME:$HOME:rw \ -v /etc/passwd:/etc/passwd:ro \ -v /etc/group:/etc/group:ro \ -v $PWD:$PWD:rw \ -w $PWD \ alpine/git \ clone [command] # Or add alias in ~/.profile (change `git` to any another keyword if git actually installed) cat >> ~/.profile << EOF function git () { (docker run -it --rm --user \$(id -u):\$(id -g) -v \$HOME:\$HOME:rw -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -v \$PWD:\$PWD:rw -w \$PWD alpine/git "\$@") } EOF source ~/.profile # and use via alias git clone git@githab.com:foob/bar.git . git pull

That's all. Check it. :), (*27)

The Versions

26/07 2018

dev-master

9999999-dev

Universal docker server, Nginx, PHP-FPM, MySql, Redis

  Sources   Download

BSD-3-Clause

by Matthew Patell

php redis server docker mysql fpm nginx docker-compose