Containers cannot reach one another when running phpunit tests via WSL interpreter when Docker is installed in WSL (not Windows)

I've spent quite a bit of time trying to find an example of somebody else trying to make this work, and have come up empty. In every other example I can find, the user has installed Docker for Windows.

By contrast, I have installed the Docker binaries in WSL only, specifically because overall performance it is significantly faster when my project source resides in the WSL volume and Docker is also running in WSL.

This setup works perfectly fine with respect to running the application in a browser.

However, when I run phpunit, the various Docker containers cannot reach each other over the Docker network. I get errors like this:

php_network_getaddresses: getaddrinfo for redis failed: Name or service not known

This sort-of makes sense, because it seems like PhpStorm is actually invoking phpunit from within the context of the WSL host OS, e.g., Ubuntu 20.04, as can be seen in the actual command that it executes:

[\\wsl$\Ubuntu-20.04]:/usr/bin/php --distribution Ubuntu-20.04 --exec /bin/sh -c "export TERM=xterm && export IDE_PHPUNIT_CUSTOM_LOADER=/home/ben/project/vendor/autoload.php && cd /home/ben/project/tests && /usr/bin/php /home/ben/project/vendor/phpunit/phpunit/phpunit --configuration /home/ben/project/tests/phpunit.xml --teamcity"

In other words, it doesn't seem like PhpStorm is actually logging into the application container to execute `phpunit`.

After digging deeper, I thought that I had perhaps chosen the wrong interpreter type when I chose "WSL". So, instead, I chose "Docker", and set the Server to the Docker app container in which the php binary resides. But, the result is more or less the same (albeit with a slightly different command invoked):

[docker://project-php:latest/]:php /opt/project/vendor/phpunit/phpunit/phpunit --configuration /opt/project/tests/phpunit.xml --teamcity

This seems a bit closer to what I expect. PhpStorm appears to create a "helper" Docker container that runs in the appropriate context, but for whatever reason, it can't reach my app's other service containers either.

Am I overlooking something? Or am I trying to do something that isn't possible?

Thanks in advance for any insight!

 

2

Sorry, missed this thread! Is the issue still actual?

1

SOLVED: while I was collecting debug information below, I found that for PHPStorm helper container Docker does not create correct network settings. I set manually in “Settings | Test Frameworks | MySetting | Docker Container | network mode” the actual name of network “datahost_default” (by default there was “bridge”) as in network setting from mariadb container and now all works fine.

It looks like the setting “network mode” is misleading in it's name and default value.

----

Original message:

Yes, the issue is still actual. I have faced it now.  

PhpStorm 2023.3.4
Build #PS-233.14475.35, built on February 13, 2024
Licensed to ********
You have a perpetual fallback license for this version.
Subscription is active until February 11, 2025.
Runtime version: 17.0.10+1-b1087.17 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 14.2.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 8
Metal Rendering is ON
Registry:
 run.processes.with.pty=TRUE
Non-Bundled Plugins:
 com.intellij.ideolog (222.3.1.0)
 net.seesharpsoft.intellij.plugins.csv (3.2.3-233)

 

Docker:
Version 4.28.0 (139021)
Engine: 25.0.3
Compose: v2.24.6-desktop.1
Credential Helper: v0.8.1
Kubernetes: v1.29.1


Docker run command:

[docker://datahost-apache-php:latest/]:php /var/www/tmp/vendor/phpunit/phpunit/phpunit --configuration /var/www/tmp/tests/phpunit.default.xml --test-suffix DataPipelineFilterTest.php /var/www/tmp/tests/Class/DataPipeline --teamcity
Testing started at 2:23 PM ...
PHPUnit 11.0.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.9
Configuration: /var/www/tmp/tests/phpunit.default.xml

PHP Warning:  mysqli::__construct(): php_network_getaddresses: getaddrinfo for mariadb failed: Name or service not known in /var/www/tmp/vendor/p/p-core/src/Class_Service/DB/DB_MYSQLi.php on line 87

 

All works fine through browser or CLI.

Tests work fine if I run them through console:

docker container exec datahost_apache-php /var/www/tmp/vendor/phpunit/phpunit/phpunit --configuration /var/www/tmp/tests/phpunit.default.xml /var/www/tmp/tests/Class/DataPipeline

PHPUnit 11.0.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.9
Configuration: /var/www/tmp/tests/phpunit.default.xml

FR                                                                  2 / 2 (100%)

 

Network Container Info of mariadb container

"NetworkSettings": {
		"Bridge": "",
		"SandboxID": "8a2120377241cf7a8d199db30a0dc54c42ebc3becbc762a6768ecc48de22b473",
		"SandboxKey": "/var/run/docker/netns/8a2120377241",
		"Ports": {
			"3306/tcp": [
				{
					"HostIp": "0.0.0.0",
					"HostPort": "3308"
				}
			]
		},
		"HairpinMode": false,
		"LinkLocalIPv6Address": "",
		"LinkLocalIPv6PrefixLen": 0,
		"SecondaryIPAddresses": null,
		"SecondaryIPv6Addresses": null,
		"EndpointID": "",
		"Gateway": "",
		"GlobalIPv6Address": "",
		"GlobalIPv6PrefixLen": 0,
		"IPAddress": "",
		"IPPrefixLen": 0,
		"IPv6Gateway": "",
		"MacAddress": "",
		"Networks": {
			"datahost_default": {
				"IPAMConfig": null,
				"Links": null,
				"Aliases": [
					"datahost-mariadb-1",
					"mariadb",
					"eacb6488051b"
				],
				"MacAddress": "02:42:c0:a8:10:03",
				"NetworkID": "ce35b339769d353ab7e9f43b2a002c444d2d38dc935d91d92acaca97336b91d5",
				"EndpointID": "2185851a845b471e601c9a4f25fb3c8499abca3ecfaaa8d6d392ddb0bb8048cd",
				"Gateway": "192.168.16.1",
				"IPAddress": "192.168.16.3",
				"IPPrefixLen": 20,
				"IPv6Gateway": "",
				"GlobalIPv6Address": "",
				"GlobalIPv6PrefixLen": 0,
				"DriverOpts": null,
				"DNSNames": [
					"datahost-mariadb-1",
					"mariadb",
					"eacb6488051b"
				]
			}
		}
	}

Container Info phpstorm_helpers_PS-233.14475.35

{
	"Id": "fddbb1ad02bf559f01611449527fd6cded783e03a0c917ac25db75944b0d3890",
	"Created": "2024-03-04T12:27:06.322763506Z",
	"Path": "/bin/sh",
	"Args": [],
	"State": {
		"Status": "created",
		"Running": false,
		"Paused": false,
		"Restarting": false,
		"OOMKilled": false,
		"Dead": false,
		"Pid": 0,
		"ExitCode": 0,
		"Error": "",
		"StartedAt": "0001-01-01T00:00:00Z",
		"FinishedAt": "0001-01-01T00:00:00Z"
	},
	"Image": "sha256:93468b0d4319bb1315bf1c4d53722c0024389363cfc52936f6c4ce42bf6b4b5a",
	"ResolvConfPath": "",
	"HostnamePath": "",
	"HostsPath": "",
	"LogPath": "/var/lib/docker/containers/fddbb1ad02bf559f01611449527fd6cded783e03a0c917ac25db75944b0d3890/fddbb1ad02bf559f01611449527fd6cded783e03a0c917ac25db75944b0d3890-json.log",
	"Name": "/phpstorm_helpers_PS-233.14475.35",
	"RestartCount": 0,
	"Driver": "overlay2",
	"Platform": "linux",
	"MountLabel": "",
	"ProcessLabel": "",
	"AppArmorProfile": "",
	"ExecIDs": null,
	"HostConfig": {
		"Binds": [],
		"ContainerIDFile": "",
		"LogConfig": {
			"Type": "json-file",
			"Config": {}
		},
		"NetworkMode": "default",
		"PortBindings": null,
		"RestartPolicy": {
			"Name": "no",
			"MaximumRetryCount": 0
		},
		"AutoRemove": false,
		"VolumeDriver": "",
		"VolumesFrom": null,
		"ConsoleSize": [
			0,
			0
		],
		"CapAdd": null,
		"CapDrop": null,
		"CgroupnsMode": "private",
		"Dns": null,
		"DnsOptions": null,
		"DnsSearch": null,
		"ExtraHosts": null,
		"GroupAdd": null,
		"IpcMode": "private",
		"Cgroup": "",
		"Links": null,
		"OomScoreAdj": 0,
		"PidMode": "",
		"Privileged": false,
		"PublishAllPorts": false,
		"ReadonlyRootfs": false,
		"SecurityOpt": null,
		"UTSMode": "",
		"UsernsMode": "",
		"ShmSize": 67108864,
		"Runtime": "runc",
		"Isolation": "",
		"CpuShares": 0,
		"Memory": 0,
		"NanoCpus": 0,
		"CgroupParent": "",
		"BlkioWeight": 0,
		"BlkioWeightDevice": null,
		"BlkioDeviceReadBps": null,
		"BlkioDeviceWriteBps": null,
		"BlkioDeviceReadIOps": null,
		"BlkioDeviceWriteIOps": null,
		"CpuPeriod": 0,
		"CpuQuota": 0,
		"CpuRealtimePeriod": 0,
		"CpuRealtimeRuntime": 0,
		"CpusetCpus": "",
		"CpusetMems": "",
		"Devices": null,
		"DeviceCgroupRules": null,
		"DeviceRequests": null,
		"MemoryReservation": 0,
		"MemorySwap": 0,
		"MemorySwappiness": null,
		"OomKillDisable": false,
		"PidsLimit": null,
		"Ulimits": null,
		"CpuCount": 0,
		"CpuPercent": 0,
		"IOMaximumIOps": 0,
		"IOMaximumBandwidth": 0,
		"MaskedPaths": [
			"/proc/asound",
			"/proc/acpi",
			"/proc/kcore",
			"/proc/keys",
			"/proc/latency_stats",
			"/proc/timer_list",
			"/proc/timer_stats",
			"/proc/sched_debug",
			"/proc/scsi",
			"/sys/firmware",
			"/sys/devices/virtual/powercap"
		],
		"ReadonlyPaths": [
			"/proc/bus",
			"/proc/fs",
			"/proc/irq",
			"/proc/sys",
			"/proc/sysrq-trigger"
		]
	},
	"GraphDriver": {
		"Data": {
			"LowerDir": "/var/lib/docker/overlay2/2673c4e2ea22a8a395871ffb250faf7cd3b5bcb0f6212e5a6ad74652cc4641ed-init/diff:/var/lib/docker/overlay2/015bf574f0265f35d1c63a5f86fe6cda93c2eeefb24b46efe48a0c124959c6d2/diff:/var/lib/docker/overlay2/24d615fb7b056d218b9aea77cf4b183436050c513e0da4d1140c6e8ad8fe617b/diff:/var/lib/docker/overlay2/bcd8c7e35f6272515ae95bc2cfcaff921f967f29bbcc8a5c67d44dd3bfb72d63/diff",
			"MergedDir": "/var/lib/docker/overlay2/2673c4e2ea22a8a395871ffb250faf7cd3b5bcb0f6212e5a6ad74652cc4641ed/merged",
			"UpperDir": "/var/lib/docker/overlay2/2673c4e2ea22a8a395871ffb250faf7cd3b5bcb0f6212e5a6ad74652cc4641ed/diff",
			"WorkDir": "/var/lib/docker/overlay2/2673c4e2ea22a8a395871ffb250faf7cd3b5bcb0f6212e5a6ad74652cc4641ed/work"
		},
		"Name": "overlay2"
	},
	"Mounts": [
		{
			"Type": "volume",
			"Name": "61859c2d2e64d829f5554f2019e7e6f7c8817ed82857bf3deee6ad94a028818d",
			"Source": "/var/lib/docker/volumes/61859c2d2e64d829f5554f2019e7e6f7c8817ed82857bf3deee6ad94a028818d/_data",
			"Destination": "/opt/.phpstorm_helpers",
			"Driver": "local",
			"Mode": "",
			"RW": true,
			"Propagation": ""
		}
	],
	"Config": {
		"Hostname": "fddbb1ad02bf",
		"Domainname": "",
		"User": "",
		"AttachStdin": true,
		"AttachStdout": false,
		"AttachStderr": false,
		"Tty": false,
		"OpenStdin": true,
		"StdinOnce": false,
		"Env": [
			"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
			"PHPSTORM_HELPERS_DIRECTORY=/opt/.phpstorm_helpers"
		],
		"Cmd": [
			"/bin/sh"
		],
		"Image": "phpstorm_helpers:PS-233.14475.35",
		"Volumes": {
			"/opt/.phpstorm_helpers": {}
		},
		"WorkingDir": "/opt/.phpstorm_helpers",
		"Entrypoint": null,
		"OnBuild": null,
		"Labels": {
			"com.jetbrains.docker.helper.image": "",
			"com.jetbrains.phpstorm_helpers.version": "PS-233.14475.35"
		}
	},
	"NetworkSettings": {
		"Bridge": "",
		"SandboxID": "",
		"SandboxKey": "",
		"Ports": {},
		"HairpinMode": false,
		"LinkLocalIPv6Address": "",
		"LinkLocalIPv6PrefixLen": 0,
		"SecondaryIPAddresses": null,
		"SecondaryIPv6Addresses": null,
		"EndpointID": "",
		"Gateway": "",
		"GlobalIPv6Address": "",
		"GlobalIPv6PrefixLen": 0,
		"IPAddress": "",
		"IPPrefixLen": 0,
		"IPv6Gateway": "",
		"MacAddress": "",
		"Networks": {
			"bridge": {
				"IPAMConfig": null,
				"Links": null,
				"Aliases": null,
				"MacAddress": "",
				"NetworkID": "",
				"EndpointID": "",
				"Gateway": "",
				"IPAddress": "",
				"IPPrefixLen": 0,
				"IPv6Gateway": "",
				"GlobalIPv6Address": "",
				"GlobalIPv6PrefixLen": 0,
				"DriverOpts": null,
				"DNSNames": null
			}
		}
	}
}

 

0

请先登录再写评论。