pour le dev
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
# 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
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
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");
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"
},
// ...
],
-
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 } },
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>
Both locations aliases and PHP versions are defined in nginx/conf.d/default.conf
(or whatever filename.conf)
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
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
docker-compose build --pull
docker-compose up -d --no-deps --build <service_name>
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
A very useful tool is used now to install them : docker-php-extension-installer
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.
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 detachdocker-compose down
stop + removedocker-compose start
docker-compose stop
docker exec -ti php72 <shell command>
execute interactively through TTY inside the containerphp72
the given commanddocker logs -f mysql_57
docker exec -ti -w /var/www/chemin_working_dir/ php74 command
exécution d'une commande, par ex: composerdocker -exec -ti -u 0 php72 <shell command>
run as root
This material comes under license MIT.