简体   繁体   中英

What equivalent in Docker.DotNet (NET CORE) docker parameters --expose=[] and -p=[]

I try to use NET CORE package https://github.com/dotnet/Docker.DotNet to start docker container from NET CORE. Usually my command line looks as

sudo docker run -it \
--name digiwage.$(date +%Y-%m-%d-%H.%M.%S) \
--expose='46003' \
-p '157.XX.XX.85:46003:46003' \
 XXXXXX/daemon:latest

following docker documentation https://docs.docker.com/engine/reference/run/#expose-incoming-ports docker has are two parameters related to port

--expose=[] Expose a port or a range of ports inside the container
-p=[] Publish a container's port or a range of ports to the host

First one is docker exposed port list, second one is ports publishing to docker host. This is different meaning, for example docker host can have a lot of IP address and we need to publish port only to one IP.

I try to start container in this way

    Dim ExposedPorts = New Dictionary(Of String, EmptyStruct)
    ExposedPorts.Add("157.XX.XX.85:46004:46004", New EmptyStruct)
    Dim Prm = New CreateContainerParameters With {
                  .Image = "alexev275/digiwage:latest",
                  .Name = $"digiwage.{Guid.NewGuid}",
                  .Env = New List(Of String),
                  .ExposedPorts = ExposedPorts,
                  .Tty = True
    }

and see in console zero as docker port parameters

在此处输入图像描述

I have expected two parameters related to port in CreateContainerParameters, but no, second parameters is absent.

在此处输入图像描述

I found workable solution.

在此处输入图像描述

    Dim ExposedPorts = New Dictionary(Of String, EmptyStruct)
    Dim ContainerPort = "46003"
    ExposedPorts.Add(ContainerPort, New EmptyStruct)

    Dim OneHostBinding As New PortBinding With {.HostIP = "157.XX.XX.86", .HostPort = "46003"}
    Dim HostBindingList As New List(Of PortBinding)
    HostBindingList.Add(OneHostBinding)
    Dim PortBindings As New Dictionary(Of String, IList(Of PortBinding))
    PortBindings.Add("46003", HostBindingList)

    Dim Labels = New Dictionary(Of String, String)
    Labels.Add("TstKey", "TstVal")
    Dim CMD = New List(Of String)
    CMD.Add("pwd")
    Dim Prm = New CreateContainerParameters With {
                  .Image = "alexev275/digiwage:latest",
                  .Name = $"digiwage.{Guid.NewGuid}",
                  .Env = Env,
                  .ExposedPorts = ExposedPorts,
                  .Labels = Labels,
                  .Tty = True,
                  .HostConfig = New HostConfig With {.PortBindings = PortBindings}
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM