Accessing host from container #447
-
Is there a recommended (cross-platform) way how to access host from a container? On Windows OS it works with My use case is that I have Pact's mock server running on host machine. It can either listen on docker container run --rm my_image:tag -u mock-server.url # other arguments I'm aware that I might need to replace the mock server with a Docker container, but I'm interested if there's a way with the current setup. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think for Linux, there is no default DNS name. I don't know much about the GitLab environment, but if you have a running container, you should get the host address from the If your service listens on |
Beta Was this translation helpful? Give feedback.
I think for Linux, there is no default DNS name. I don't know much about the GitLab environment, but if you have a running container, you should get the host address from the
Hostname
property:https://github.com/HofmeisterAn/dotnet-testcontainers/blob/de4c4a251152ee2cfdcd4061c8b1bcc0621e692f/src/DotNet.Testcontainers/Containers/TestcontainersContainer.cs#L85
If your service listens on
0.0.0.0
, you should be able to access it. The Kafka configuration, for instance, uses the property during the container start to configure it own services:https://github.com/HofmeisterAn/dotnet-testcontainers/blob/de4c4a251152ee2cfdcd4061c8b1bcc0621e692f/src/DotNet.Testcontainers/Configurations/Modules/Mes…