testcontainers-java: Can not set custom container name

Tried to set container name via .setContainerName(), however upon start container still has some random name assigned to it automatically. Did anyone test this? Works from command line with docker run -d --name bla my/image

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

Dont mind. I found a nice workaround:

            .withCreateContainerCmdModifier(new Consumer<CreateContainerCmd>() {
                @Override
                public void accept(CreateContainerCmd createContainerCmd) {
                    createContainerCmd.withHostName(CNAME);
                    createContainerCmd.withName(CNAME);
                }
            })

The documentation of withCreateContainerCmdModifier says:

Warning: this does expose the underlying docker-java API so might change outside of our control.

To me, this seems like a strong indication for extending the interface of GenericContainer.

IMHO there is always a way to screw things up when configuring containers and hiding existing docker functionality isn’t gonna make testcontainers more valuable. Also it would make sense adding container labelling.

I’m initializing cluster of 3 etcd nodes, where I should link them during start command and this .withNetworkAliases("foo") works perfectly for me, thanks!