testcontainers / testcontainers/testcontainers-php
No host port mapping after creating container
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 215
- Forks
- 34
- Avg merge
- 1h 59m
- Merged PRs (30d)
- 3
Description
I noticed when creating a new MySQLContainer like so
protected function setUp(): void
{
$this->container = MySQLContainer::make();
$this->container->withMySQLDatabase('pimcore');
$this->container->withMySQLUser('pimcore_user', 'pimcore');
try {
$this->container->run();
} catch (JsonException $e) {
$this->fail($e->getMessage());
}
}
but when checking out the docker container with docker ps and docker inspect there is no port mapped to the host (localhost). And then when I try to connect to it like so
$this->pdo = new PDO(
sprintf('mysql:host=%s;port=3306', $this->container->getAddress()),
'pimcore_user',
'pimcore',
);
host missing when inspecting the container
"Ports": {
"3306/tcp": null,
"33060/tcp": null
},
I get this timeout error
1) Tests\App\journey\ContactIntegrationTest::testGetAllAction
PDOException: SQLSTATE[HY000] [2002] Operation timed out
here the container in Docker Desktop
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with MySQLContainer::make(), run(), and getAddress(), then compare the container's Docker port configuration with the reported docker inspect output. Reproduce the PDO connection using the shown setup and verify the expected host and port mapping; the issue is done when the container can be reached from the host without the timeout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, mysql, php
- Domain
- databases, devops, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100