Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: DB2 does not start tcpip listener if container.withCreateContainerCmdModifier is used to do port mapping #7679

Closed
filipelautert opened this issue Oct 17, 2023 · 3 comments

Comments

@filipelautert
Copy link

Module

DB2

Testcontainers version

1.19.1

Using the latest Testcontainers version?

Yes

Host OS

Windows, Linux, MacOsX

Host Arch

Docker version

Docker version 24.0.6, build ed223bc

What happened?

DB2 fails to start tcpip listener on port 50000 .

Relevant log output

2023-10-17 19:35:20 DB2 has not been started
2023-10-17 19:35:20 Starting DB2...
2023-10-17 19:35:20 
2023-10-17 19:36:20 10/17/2023 22:36:20     0   0   SQL1042C  An unexpected system error occurred.
2023-10-17 19:36:20 SQL1032N  No start database manager command was issued.  SQLSTATE=57019
2023-10-17 19:36:20 (*) User chose to create lbcat database

In the docker logs, the "No start database manager command was issued" is not expected. But startup process continues and eventually it finishes successfully - besides tcpip listener is not started. You can connect to the container and confirm that with "netstat -na" (port 50000 won't show, only 22)

Additional Information

Adding port mappings to the container using container.withCreateContainerCmdModifier() triggers the issue.

Below there is a sample code that produces the error:

        Db2Container container = new Db2Container()
                .withUsername("lbuser")
                .withPassword("lbpass")
                .withDatabaseName("lbcat")
                .acceptLicense();

        List<PortBinding> portBindings = Collections.singletonList(new PortBinding(Ports.Binding.bindPort(50000), new ExposedPort(50000)));
        container.withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(new HostConfig().withPortBindings(portBindings)));
        container.start();

If I exclude the container.withCreateContainerCmdModifier db2 starts just fine. In Liquibase test suite we do this as part of our startup method for all of our integration test databases (postgresql, mysql, mssql, etc) but just db2 has startup problems.

@eddumelendez
Copy link
Member

Can you share what are you trying to achieve? Currently, Db2Container already expose port 50000 but through a random port when calling getJdbcUrl(). Fixed port is a bad practice not recommended by Testcontainers. If fixed port is required for debugging purposes, I would recommend to use Testcontainers Desktop

@eddumelendez eddumelendez closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2023
@filipelautert
Copy link
Author

Hello @eddumelendez - we have this generic code around here that maps all exposed ports to local ones. It's been used with other docker containers, but it only cause issues to db2 one.
In fact we already have a workaround for that but we just wanted to report this odd behavior as we saw that more people faced similar issues.

@eddumelendez
Copy link
Member

If doing so, you should know what are you doing. Check the second example using cmd.getHostConfig() in https://java.testcontainers.org/features/advanced_options/. I think it should be related to the remapping port but IMHO that's not the use for Testcontainers modules.

Also, it is highly recommended to declare the image in the constructor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants