I'm trying to dynamically create a container from another container and I'm getting SocketException which suggesting sth is incorrect with docker network configuration.
Crate a docket image that do sth (in my case it's getting some O365 data via Graph API). The image is called "trace".
Create another docket image (called "trace-runner") that dynamically (via api) creates a container from "trace" image.
Run a container from "trace-runner" image.
Make sure both containers run on the same network bridge so that they can talk each other via IP or name (use --network option).
What actually happened?:
SocketException is thrown:
System.Net.Sockets.SocketException (99): Cannot assign requested address
2023-06-13 18:01:31 at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.CreateException(SocketError error, Boolean forAsyncThrow)
2023-06-13 18:01:31 at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ConnectAsync(Socket socket)
2023-06-13 18:01:31 at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP, CancellationToken cancellationToken)
2023-06-13 18:01:31 at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP)
2023-06-13 18:01:31 at System.Net.Sockets.SocketTaskExtensions.ConnectAsync(Socket socket, EndPoint remoteEP)
2023-06-13 18:01:31 at Docker.DotNet.DockerClient.<>cDisplayClass6_0.<<-ctor>b1>d.MoveNext()
2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
2023-06-13 18:01:31 at Docker.DotNet.DockerClient.<>cDisplayClass6_0.<.ctor>b1(String host, Int32 port, CancellationToken cancellationToken)
2023-06-13 18:01:31 at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
2023-06-13 18:01:31 at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2023-06-13 18:01:31 at Microsoft.Net.Http.Client.ManagedHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
2023-06-13 18:01:31 at Microsoft.Net.Http.Client.ManagedHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2023-06-13 18:01:31 at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2023-06-13 18:01:31 at System.Net.Http.HttpClient.gCore|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
2023-06-13 18:01:31 at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
2023-06-13 18:01:31 at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
2023-06-13 18:01:31 at Docker.DotNet.DockerClient.PrivateMakeRequestAsync(TimeSpan timeout, HttpCompletionOption completionOption, HttpMethod method, String path, IQueryString queryString, IDictionary2 headers, IRequestContent data, CancellationToken cancellationToken) 2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) 2023-06-13 18:01:31 at Docker.DotNet.DockerClient.PrivateMakeRequestAsync(TimeSpan timeout, HttpCompletionOption completionOption, HttpMethod method, String path, IQueryString queryString, IDictionary2 headers, IRequestContent data, CancellationToken cancellationToken)
2023-06-13 18:01:31 at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary2 headers, TimeSpan timeout, CancellationToken token)
2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
2023-06-13 18:01:31 at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary2 headers, TimeSpan timeout, CancellationToken token)
2023-06-13 18:01:31 at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary2 headers, CancellationToken token)
2023-06-13 18:01:31 at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable`1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, CancellationToken token)
2023-06-13 18:01:31 at Docker.DotNet.ContainerOperations.CreateContainerAsync(CreateContainerParameters parameters, CancellationToken cancellationToken)
2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
2023-06-13 18:01:31 at Docker.DotNet.ContainerOperations.CreateContainerAsync(CreateContainerParameters parameters, CancellationToken cancellationToken)
2023-06-13 18:01:31 at Program.CreateContainer(DockerClient client, String job, String imageName, String applicationID, String tenantID, String clientSecret, String userPrincipalNames, String folderName, String terms, String dockerFolder, String localFolder) in /App/Program.cs:line 50
2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
2023-06-13 18:01:31 at Program.CreateContainer(DockerClient client, String job, String imageName, String applicationID, String tenantID, String clientSecret, String userPrincipalNames, String folderName, String terms, String dockerFolder, String localFolder)
2023-06-13 18:01:31 at Program.Main(String[] args) in /App/Program.cs:line 33
2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
2023-06-13 18:01:31 at Program.Main(String[] args)
2023-06-13 18:01:31 at Program.(String[] args)
2023-06-13 18:01:31 --- End of stack trace from previous location ---
2023-06-13 18:01:31 at Docker.DotNet.DockerClient.<>cDisplayClass6_0.<<-ctor>b__1>d.MoveNext()
2023-06-13 18:01:31 --- End of stack trace from previous location ---
2023-06-13 18:01:31 at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
What did you expect to happen?:
"trace" container is created.
Additional information:
The code from "trace-runner" image that creates a container from "trace" image:
internal static async Task<string> CreateContainer (DockerClient client, string job, string imageName, string applicationID, string tenantID, string clientSecret, string userPrincipalNames, string folderName, string terms, string dockerFolder, string localFolder)
{
string networkName = "trace";
var response = await client.Containers.CreateContainerAsync(new CreateContainerParameters()
{
Image = imageName, // "trace-image",
Name = applicationID + "_" + job,
HostConfig = new HostConfig
{
AutoRemove = true,
Binds = new List<string>
{
localFolder + ":" + dockerFolder
},
NetworkMode = networkName // "trace"
},
Cmd = new List<string>
{
applicationID, // Graph API params: credentials - app ID
tenantID, // Graph API params: credentials - tenant ID
clientSecret, // Graph API params: credentials - secret
userPrincipalNames, // Graph API params: mailboxes to get data from
folderName, // Graph API params: mailbox folder
job, // Graph API params: date
terms, // Graph API params: others
dockerFolder + "/" + imageName// "/var/lib/docker/volumes/_data/trace-image" // output folder
}
});
return response.ID;
}
docker file to create "trace-runner" image container:
Output of
dotnet --info
:What version of Docker.DotNet?:
Steps to reproduce the issue:
I'm trying to dynamically create a container from another container and I'm getting SocketException which suggesting sth is incorrect with docker network configuration.
What actually happened?:
SocketException is thrown:
System.Net.Sockets.SocketException (99): Cannot assign requested address 2023-06-13 18:01:31 at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.CreateException(SocketError error, Boolean forAsyncThrow) 2023-06-13 18:01:31 at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ConnectAsync(Socket socket) 2023-06-13 18:01:31 at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP, CancellationToken cancellationToken) 2023-06-13 18:01:31 at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP) 2023-06-13 18:01:31 at System.Net.Sockets.SocketTaskExtensions.ConnectAsync(Socket socket, EndPoint remoteEP) 2023-06-13 18:01:31 at Docker.DotNet.DockerClient.<>cDisplayClass6_0.<<-ctor>b1>d.MoveNext() 2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) 2023-06-13 18:01:31 at Docker.DotNet.DockerClient.<>cDisplayClass6_0.<.ctor>b1(String host, Int32 port, CancellationToken cancellationToken) 2023-06-13 18:01:31 at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) 2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) 2023-06-13 18:01:31 at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) 2023-06-13 18:01:31 at Microsoft.Net.Http.Client.ManagedHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) 2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) 2023-06-13 18:01:31 at Microsoft.Net.Http.Client.ManagedHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) 2023-06-13 18:01:31 at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) 2023-06-13 18:01:31 at System.Net.Http.HttpClient.gCore|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
2023-06-13 18:01:31 at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
2023-06-13 18:01:31 at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
2023-06-13 18:01:31 at Docker.DotNet.DockerClient.PrivateMakeRequestAsync(TimeSpan timeout, HttpCompletionOption completionOption, HttpMethod method, String path, IQueryString queryString, IDictionary(String[] args)
2023-06-13 18:01:31 --- End of stack trace from previous location ---
2023-06-13 18:01:31 at Docker.DotNet.DockerClient.<>c DisplayClass6_0.<<-ctor>b__1>d.MoveNext()
2023-06-13 18:01:31 --- End of stack trace from previous location ---
2023-06-13 18:01:31 at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2 headers, IRequestContent data, CancellationToken cancellationToken) 2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) 2023-06-13 18:01:31 at Docker.DotNet.DockerClient.PrivateMakeRequestAsync(TimeSpan timeout, HttpCompletionOption completionOption, HttpMethod method, String path, IQueryString queryString, IDictionary
2 headers, IRequestContent data, CancellationToken cancellationToken) 2023-06-13 18:01:31 at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary
2 headers, TimeSpan timeout, CancellationToken token) 2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) 2023-06-13 18:01:31 at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary
2 headers, TimeSpan timeout, CancellationToken token) 2023-06-13 18:01:31 at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary
2 headers, CancellationToken token) 2023-06-13 18:01:31 at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable`1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, CancellationToken token) 2023-06-13 18:01:31 at Docker.DotNet.ContainerOperations.CreateContainerAsync(CreateContainerParameters parameters, CancellationToken cancellationToken) 2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) 2023-06-13 18:01:31 at Docker.DotNet.ContainerOperations.CreateContainerAsync(CreateContainerParameters parameters, CancellationToken cancellationToken) 2023-06-13 18:01:31 at Program.CreateContainer(DockerClient client, String job, String imageName, String applicationID, String tenantID, String clientSecret, String userPrincipalNames, String folderName, String terms, String dockerFolder, String localFolder) in /App/Program.cs:line 50 2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) 2023-06-13 18:01:31 at Program.CreateContainer(DockerClient client, String job, String imageName, String applicationID, String tenantID, String clientSecret, String userPrincipalNames, String folderName, String terms, String dockerFolder, String localFolder) 2023-06-13 18:01:31 at Program.Main(String[] args) in /App/Program.cs:line 33 2023-06-13 18:01:31 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) 2023-06-13 18:01:31 at Program.Main(String[] args) 2023-06-13 18:01:31 at Program.What did you expect to happen?:
"trace" container is created.
Additional information:
The code from "trace-runner" image that creates a container from "trace" image:
docker file to create "trace-runner" image container:
Important note - everything works fine when "trace-runner" is run as an application (not as a container)!!!