Giter Club home page Giter Club logo

docker-damp's Introduction

Lamp stack

pour le dev

Installing on Windows

On Windows, it is recommanded to install Docker-desktop with WSL2

The best way is to use Chocolatey to install and update the software

choco install wsl2 docker-desktop docker-compose -y

In addition, there're some tweeks to improve performances: https://stackoverflow.com/questions/62154016/docker-on-wsl2-very-slow

Quick start

# install docker (as admin on windows):
choco install docker -y
choco install docker-compose -y

# touch env file
cp template.env .env
code .env

# touch docker-compose.yml file
cp docker-compose-dev.yml docker-compose.yml

# touch apache config
cp apache/apache.template.conf apache/conf/apache.conf
code apache/conf/apache.conf

# build & start:
docker-compose up -d

Choose your docker-compose file

docker-compose.yml comes in 2 versions:

  • dev
    • with xdebug
    • php.ini with recommanded settings for dev
    • full LAMP stack (with Apache and mySql)
  • prod
    • without xdebug
    • php.ini with recommanded settings for prod
    • only with PHP containers

Inside php

Db connexion should use service name and local port:

# docker-compose.yml
services:
    mysql57:
        ports:
        - "13306:3306"

    php74:
        depends_on:
        - mysql57
// my PHP
$cnx = new PDO("mysql:host=mysql57;port=3306", "cnx-name", "cnx-pwd");

Using composer

Composer should be used with a SSH key, witch is stored at /root/.ssh

In composer.json the option repositories should be set as this:

"repositories": [
    {
        "type": "git",
        "url": "[email protected]:takoma_fr/takoma/shared/lizy.git"
    },
    // ...
],

Using xDebug on VScode

  • PHP must be installed on host

  • Add a debug section in .vscode/launch.json;

    pathMappings is the most important property

    {
        "name": "Docker XDebug",
        "type": "php",
        "request": "launch",
        "port": 9003,
        "pathMappings": {
            "/var/www/dev/nissan/gembakaizen/api": "${workspaceFolder}"
        },
        "xdebugSettings": {
            "max_data": 65535,
            "show_hidden": 1,
            "max_children": 100,
            "max_depth": 5
        }
    },

Apache configuration

Aliases should be defined in httpd/2.4/conf.d/alias.conf, refering to /var/www/...

The version of PHP is set in the file .htaccess of each project:

<FilesMatch \.php$>
    SetHandler "proxy:fcgi://php74:9000"
</FilesMatch>

Nginx configuration

Both locations aliases and PHP versions are defined in nginx/conf.d/default.conf (or whatever filename.conf)

MySql tweaks

SELECT @@sql_mode

gives: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Adding further images

It's possible to run as many php or mysql version as needed. NOTE that adding or removing a service can make ophans. Once the docker-compose.yml is changed, it can be useful build the material, using the following command:

  • docker-compose up --build -d --remove-orphans

Update image

docker-compose build --pull

Rebuild a single service

  • docker-compose up -d --no-deps --build <service_name>

Using dockerized SMTP

In production environment, the service smtp is directly usable by other services of the docker network

Configuration setting to be used:

  • smtp address: smtp (the name of the service)
  • smtp port: left as default (25)
  • neither login nor password

PHP extensions

A very useful tool is used now to install them : docker-php-extension-installer

Logs

Docker provides a log system that store log in 1 file, unlimited length.
It is possible to change the friver and its options.
See JSON File logging driver and Logging in compose file

Various commands may help:

  • docker logs
  • docker service logs
  • docker-compose logs

TIP: use the --help option before.

TIP: in VScode, the Docker extension eases in watching logs.

Useful commands

NOTE: shell on ubuntu based image is bash, on alpine based image is /bin/sh

  • docker-compose config validate composer file (using .env)
  • docker-compose up --build -d create + start, with build, and detach
  • docker-compose down stop + remove
  • docker-compose start
  • docker-compose stop
  • docker exec -ti php72 <shell command> execute interactively through TTY inside the container php72 the given command
  • docker logs -f mysql_57
  • docker exec -ti -w /var/www/chemin_working_dir/ php74 command exécution d'une commande, par ex: composer
  • docker -exec -ti -u 0 php72 <shell command> run as root

Useful links

License

This material comes under license MIT.

docker-damp's People

Watchers

Raphaël Agostini avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.