Практически у каждого разработчика, активно использующего Docker в своей работе, есть заготовки под разные проекты. Пример ниже является неплохой основой для проекта на Yii2 с использованием шаблона Basic, хотя его можно адаптировать для Advanced или под любую другую архитектуру.
version: '3' networks: default: driver: bridge services: php: image: yiisoftware/yii2-php:7.4-apache volumes: - ~/.composer-docker/cache:/root/.composer/cache:delegated - ./:/app:delegated - ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini - ./docker/apache/000-default.conf:/etc/apache2/sites-available/000-default.conf environment: - PHP_ENABLE_XDEBUG=1 - PHP_IDE_CONFIG=serverName=MyTestServer ports: - '80:80' networks: - default depends_on: - db db: image: mysql:5.7 restart: always environment: - MYSQL_DATABASE=my_database_name - MYSQL_USER=my_user_name - MYSQL_PASSWORD=my_user_password - MYSQL_ROOT_PASSWORD=my_root_password ports: - '3306:3306' expose: - '3306' volumes: - "./docker/mysql:/var/lib/mysql" networks: - default phpmyadmin: image: phpmyadmin/phpmyadmin ports: - '8888:80' environment: - PMA_ARBITRARY=1 - PMA_HOST=db depends_on: - db
[xdebug] xdebug.mode = debug xdebug.client_host = host.docker.internal
<Directory /app/web/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /app/web # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost>
Запуск проекта
docker-compose up -d
После успешного запуска всех контейнеров сайт будет доступен в браузере по адресу 127.0.0.1, он же localhost.
http://127.0.0.1
Подключение к базе данных
КОРЕНЬ_ПРОЕКТА\config\db.phpreturn [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=db;dbname=my_database_name', 'username' => 'my_user_name', 'password' => 'my_user_password', 'charset' => 'utf8', ];
PhpMyAdmin
PhpMyAdmin будет также доступен на localhost’e, только через 8888 порт.
http://localhost:8888/
Авторизация root’a:
Сервер: db
Пользователь: root
Пароль: my_root_password
Авторизация пользователя:
Сервер: db
Пользователь: my_user_name
Пароль: my_user_password
xDebug и Docker
- Quickstart with Docker in PhpStorm (https://blog.jetbrains.com/phpstorm/2018/08/quickstart-with-docker-in-phpstorm/);
- Zero-configuration debugging (https://www.jetbrains.com/help/phpstorm/zero-configuration-debugging.html);
- Configure Xdebug (https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html#updatingPhpIni);
- Upgrading from Xdebug 2 to 3 (https://xdebug.org/docs/upgrade_guide);
- Browser debugging extensions (https://www.jetbrains.com/help/phpstorm/browser-debugging-extensions.html);
- Быстрый старт с Docker в PhpStorm (vpawd.ru/articles/quickstart_with_docker_in_phpstorm);
- Working with PhpStorm and Docker on Windows (ollyxar.com/blog/docker-phpstorm-windows);
- hub.docker.com/u/phpstorm;
- Отладка в PHP с помощью xdebug, docker, phpstorm, netbeans (https://www.youtube.com/watch?v=yiQbJG_dSIc);
- Быстрый старт Xdebug + Docker + PhpStorm (yutube.com/watch?v=9MhHQJjMulk).
Полезные ссылки
- github.com/yiisoft/yii2-docker;
- github.com/yiisoft/yii2-app-basic;
- github.com/yiisoft/yii2-app-advanced;
- Yii and Docker (yiiframework.com/doc/guide/2.0/en/tutorial-docker);
- Настройка рабочего окружения Yii2 Framework с помощью Docker Toolbox на Windows (habr.com/ru/sandbox/135380);
- Настройка рабочего окружения в Docker для yii-framework приложения (habr.com/ru/post/428688);
- Development with Yii2 and docker-compose (macklus.net/en/development/yii-framework-en/development-with-yii2-and-docker-compose).
Добавить комментарий
Для отправки комментария вам необходимо авторизоваться.