How is this possible? Testing does not use the docker container from settings

Hi everyone.

I am really confused as to how PhpStorm runs tests with Docker.

I have a Docker container that runs this command on "build" (using Lando as a wrapper):

apt-get install locales locales-all -y

When I spin up the container and run the PHPUnit tests through CLI, everything works and all tests pass.

However, I can't run those tests successfully in PhpStorm, since the locales don't appear to be installed and one of them is required for testing. To confirm this, I put 

system('locale -a');

... inside the test source, I get only


Clearly, PhpStorm is not using the container (or the volume?). Even more strange is that I can run tests in PhpStorm without the Docker container being up. If I run "docker container ls", there are zero containers online. However, PhpStorm can still run the test (and fail at it, bc of the locale not being installed).

It's bizarre since if I change the --net parameter to something random, I get the following error:

So it appears the --net parameter must be something valid, even though it appears the actual container with that network ID is not used. Even when it is set correctly, the container is not up and PhpStorm can run the test!

This is the package that is being tested and this is the test that is being run.

Below are screenshots of how I have things in PhpStorm. What am I missing?

Thanks in advance :)


PhpStorm (just like other IntelliJ-based IDEs) can't run code in an already running container in the Docker mode:
The exec mode is only supported for Docker Compose.

So, it does start a new container each time indeed.


Hi Eugene Morozov, thank you for your reply.

What exactly do you mean with

The exec mode is only supported for Docker Compose.


I have this setup:


It turns out that "lando rebuild" does not actually build a Docker image.

This problem can be solved by building a custom docker image and then selecting that one in the PhpStorm "Image name" for the CLI interpreter. That way the same image will be used on both ends.

So here's how I made it work with Lando:

1. Add these two lines to the landofile (you can obviously put a different image name that fits your project)

2. Add a Dockerfile to ./config

FROM devwithlando/php:8.1-fpm-4

RUN apt-get update -y \
&& apt-get install -y locales locales-all

3. Run 

lando rebuild

4. In PhpStorm, select the generated image for the CLI interpreter

That's it, now testing runs in the same system, no matter where you launch it :)


Please sign in to leave a comment.