Binding a port to a host interface using the REST API

后端 未结 3 2023
南笙
南笙 2021-02-05 11:08

The documentation for the commandline interface says the following:

To bind a port of the container to a specific interface of the host system, use the

3条回答
  •  独厮守ぢ
    2021-02-05 11:20

    I know this question had been answered, I using the above solution and here is how I did it in java using Docker Java Client v3.2.5

        PortBinding portBinding = PortBinding.parse( hostPort + ":" + containerPort);
        HostConfig hostConfig = HostConfig.newHostConfig()
                .withPortBindings(portBinding);
        CreateContainerResponse container =
                dockerClient.createContainerCmd(imageName)
                        .withHostConfig(hostConfig)
                        .withExposedPorts(ExposedPort.parse(containerPort+"/tcp"))
                        .exec();
    

提交回复
热议问题