Title: How to start container with Docker.DotNet (NET CORE)
Tags: c#;docker;.net-core
Question: 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' \
-e RPC_PASSWORD=$(xxd -l 32 -c 32 -p /dev/urandom) \
-e EXTERNAL_IP='157.XX.XX.85' \
-e MASTERNODE_PRIV_KEY='51kWXqrknGeLLEqnUgRBPtrBxQ3o5VBp4bkRy4fHN3ZpzURHdkr' \
-e TX_INDEX='1' \
-e SEED_NODE='95.XX.XX.73' \
-e PORT='46003' \
-e RPC_ALLOW_IP='151.154.11.224' \
-e RPC_CONNECT_IP='151.154.11.224' \
-p '157.XX.XX.85:46003:46003' \
XXXXXX/daemon:latest
There are restricted example, how is possible to start it https://github.com/dotnet/Docker.DotNet/blob/master/test/Docker.DotNet.Tests/IContainerOperationsTests.cs
But main point is absent in documentation. Firstly, 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
Unfortunately, I don't see in Docker.DotNet two different parameters, related to ports.
Second issue, this my code produced only template of containers instead working container.
Dim Env = New List(Of String)({&quot;RPC_PASSWORD=$(xxd -l 32 -c 32 -p /dev/urandom)&quot;,
&quot;EXTERNAL_IP='157.XX.XX.85'&quot;,
&quot;MASTERNODE_PRIV_KEY='51kWXqrknGeLLEqnUgRBPtrBxQ3o5VBp4bkRy4fHN3ZpzURHdkr'&quot;,
&quot;TX_INDEX='1'&quot;,
&quot;SEED_NODE='95.XX.XX.73'&quot;,
&quot;PORT='46004'&quot;,
&quot;RPC_ALLOW_IP='151.154.11.224'&quot;,
&quot;RPC_CONNECT_IP='151.154.11.224'&quot;})
Dim ExposedPorts = New Dictionary(Of String, EmptyStruct)
ExposedPorts.Add(&quot;'157.XX.XX.85:46004:46004'&quot;, New EmptyStruct)
Dim Prm = New CreateContainerParameters With {
.Image = &quot;alexev275/digiwage:latest&quot;,
.Name = $&quot;digiwage.{Guid.NewGuid}&quot;,
.Env = Env,
.ExposedPorts = ExposedPorts,
.Tty = True
Dim CreateContainer As CreateContainerResponse = DockerHub.Containers.CreateContainerAsync(Prm).Result
Dim StartResTask As Task(Of Boolean) = DockerHub.Containers.StartContainerAsync(CreateContainer.ID, New ContainerStartParameters())
StartResTask.Wait()
I don't receive errors or warning, only Status=RunToCompletion and template of container without starting.
How to really start container by https://github.com/dotnet/Docker.DotNet ?
And how to set correct parameters --expose=[] and -p=[] ?
Comment: You have two issues here: 1. your containers are exiting as soon as you start them 2. you don't know how to expose ports. Those should be 2 different questions. Anyway, you need to find the container logs and read any errors/messages logged to figure out how to fix problem 1. It might have to do with `RPC_PASSWORD=$(xxd -l 32 -c 32 -p /dev/urandom)`, which is evaluated by bash to produce a random password, but it's a literal string in .NET.

Comment: Thank you, @omajid. This is answer, of course you are right, I replace RPC_PASSWORD to normal .NET function, container started and of course you are right about log. I see log and see "Error: Invalid -rpcallowip subnet specification: '151.154.11.224'. Valid are a single IP, a network/netmask or a network/CIDR". Therefore I understand character ' need to use only for bash escaping. I also delete single quote mark and my container started! However publishing ports in docker host still wrong . This is another question. Please, set your remark as replay and I will mark your replay as solution.

Here is the accepted answer: You have two issues here:
your containers are exiting as soon as you start them
you don't know how to expose ports.
Those should be 2 different questions.
Anyway, you need to find the container logs and read any errors/messages logged to figure out how to fix problem 1. It might have to do with RPC_PASSWORD=$(xxd -l 32 -c 32 -p /dev/urandom), which is evaluated by bash to produce a random password, but it's a literal string in .NET.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:01/27/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><docker><.net-core>', 'Title': 'How to start container with Docker.DotNet (NET CORE)', 'ViewCount': 425, 'id': 70886564, 'user_AboutMe': '', 'user_AccountId': 21530792.0, 'user_DisplayName': 'Alex', 'user_Reputation': 89.0, 'user_Views': 33.0, 'user_id': 15870284.0}}