problem accessing mysql container from php container in intellij idea
Hi
I have the following composer file with a predefined network. When I use `composer test` inside the PHP container, everything works fine and tests - including those that require the MySQL container - execute. Still, it fails when I want to complete the same flow from the debug/run configurations. I would appreciate any help on this.
debug/run config: https://ibb.co/mJFrny5
docker-compose.yaml
version: '3'
volumes:
redis_data:
driver: local
mysql_data:
driver: local
services:
package_web:
restart: unless-stopped
build:
context: ./docker/web
dockerfile: Dockerfile
args:
- WWW_DATA_USER=${APP_UID}
- WWW_DATA_GROUP=${APP_GID}
- ENVIRONMENT=${APP_ENV}
expose:
- "80"
- "443"
volumes:
- ./:/var/www/
- ./docker/web/nginx.conf:/etc/nginx/nginx.conf
- ./docker/web/site.conf:/etc/nginx/sites-enabled/site.conf
ports:
- "8305:80"
package_php:
restart: unless-stopped
build:
context: .
dockerfile: ./docker/php/Dockerfile
args:
- WWW_DATA_USER=${APP_UID}
- WWW_DATA_GROUP=${APP_GID}
- ENVIRONMENT=${APP_ENV}
expose:
- "9000"
environment:
- WWW_DATA_USER=${APP_UID}
volumes:
- ./:/var/www
- ./docker/php/php-fpm.conf:/usr/local/etc/php-fpm.conf
- ./docker/php/php_prod.ini:/usr/local/etc/php/conf.d/custom.ini
- ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
package_redis:
image: redis:6.2.6
restart: unless-stopped
volumes:
- redis_data:/data
ports:
- "8307:6379"
package_mysql:
restart: unless-stopped
build:
context: ./docker/mysql
dockerfile: Dockerfile
args:
- UID=${APP_UID}
- GID=${APP_GID}
environment:
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
ports:
- "8306:3306"
volumes:
- mysql_data:/var/lib/mysql
- ./docker/mysql/config.ini:/etc/mysql/conf.d/config.ini
networks:
default:
external:
name: my_package
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<testsuites>
<testsuite name="Package">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory>src/</directory>
</include>
</coverage>
<php>
<server name="APP_ENV" value="testing"/>
<server name="DB_CONNECTION" value="mysql"/>
<!-- also tested localhost(connection refused), -->
<!-- container-ip (connection timeout) with DB_PORT 3306 -->
<!-- docker service name (php_network_getaddresses: getaddrinfo failed: Name or service not known)-->
<server name="DB_HOST" value="127.0.0.1"/>
<server name="DB_USERNAME" value="root"/>
<server name="DB_PORT" value="8306"/>
<server name="DB_PASSWORD" value="some-strong-password"/>
<server name="DB_DATABASE" value="laravel"/>
</php>
</phpunit>
Please sign in to leave a comment.
Normally, Docker Compose services know each other by their names, in which case the DB service should be called by
package_mysqland not bymysql.Besides that, please double-check that in PhpStorm, you are using a Docker Compose interpreter in the
execmode, not a plain Docker interpreter and not a Docker Compose interpreter in therunmode.Thanks for the response, I'm not sure I understand. What do you mean by running Docker Compose interpreter in the `exec` mode?
I'm getting the interpreter, from a PHP Docker container.
I would appreciate it if you explain it more.
Exactly that. Please check this guide, the "Docker Compose" tab.
Thank you
I'll look into it