Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
175 lines (156 sloc) 4.6 KB

Docker Compose for local development

  • https ready!
  • multiple domain / project support
  • PHP Xdebug

reference from https://laradock.io

Index

Setup

  • download & install docker for MAX(os x)

    https://docs.docker.com/docker-for-mac/

  • fork & clone this repository

    $ git clone https://github.com/cscolabear/docker-dev.git Projects
    
    # [optional] change branch, if you need mysql
    $ git checkout service/add-mysql
  • make your folder look like this... (👉 replace ~/Projects what you want.)

    e.g.

    ~/Projects

    ~/Projects/[your project - 1]

    ~/Projects/[your project - 2]

    docker-for-local-dev-folder

  • Build Images & Container

    $ cd ~/Projects
    $ chmod -R 755 Logs
    $ dokcer-compose up -d

    Please wait

  • SSH into a container

    $ cd ~/Projects/ && clear && docker-compose exec workspace bash

    looked like after connected~ docker-for-local-dev-ssh-into you can execute composer, node, npm in here

  • enjoy Docker 🐳

    👉 create index.php & index.html in ~/Projects

    use command~

    $ echo -e "<?php\nphpinfo();" > index.php
    $ echo "<h1>127.0.0.1 - fine</h1>" > index.html

    open browser - http://localhost or https://localhost

    docker-localhost-idnex-php

    index.html > https://localhost/index.html) docker-for-local-dev-ssh-localhost

Usage

  • Add Nginx Virtual Host

    • creating a new vhost.conf file in ~/Projects/Dockerfiles/nginx/sites-enabled/

      nginx conf tools: https://nginxconfig.io

    • modify /etc/hosts (mac / os x)
      C:\WINDOWS\system32\drivers\etc\hosts (windows 10)

      add domain at the bottom

      127.0.0.1    local.[any_you_want_domain_1]
      127.0.0.1    local.[any_you_want_domain_2]
      
    • add host at the docker-compose.yml

      add host domain at, services > fpm > extra_hosts

      add new line

      - "local.[any_you_want_domain_1]:172.16.1.50"
      

      looks like this host-compose-yml

    • restart nginx Docker Container

      $ docker-compose restart nginx
  • Change PHP Configuration

    • modify Dockerfiles/php-fpm/php.ini
    • restart php-fpm Docker Container
    $ docker-compose restart fpm
    

Info

  • What's in there?

    • nginx
      • nginx:alpine
      • https, http2
      • logrotate
    • php-fpm
      • php:7.2-fpm
    • workspace
      • nvm 0.34.0
      • node v10.15.3
      • npm 6.4.1
  • ~/Projects/Logs/ - nginx log file path

    e.g.

    ~/Projects/Logs/error.log

    ~/Projects/Logs/nginx-access.log

    ~/Projects/Logs/nginx-error.log

  • docker image size

    docker-image-size

  • Xdebug & VSCode

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Listen for > XDebug",
                "type": "php",
                "request": "launch",
                "port": 9001,
                "pathMappings": {
                    "/var/www": "$> {workspaceRoot}"
                },
                "log": true
            },
            {
                "name": "Launch > currently open script",
                "type": "php",
                "request": "launch",
                "program": "${file}",
                "cwd": "${fileDirname}",
                "port": 9001
            }
        ]
    }
You can’t perform that action at this time.