I'm trying to run multiple instances of a Docker image on a single node and send requests to the node allowing Docker to load balance between the instances.
If I use the Run command shown below the container behaves as expected, I can send a request from another machine on port 80 and the request is serviced by container. However, if I try to spin up a service with the Service command shown below I do get 5 replicated tasks running but the request only returns a 404 error.
How can I communicate with the service through my exposed port?
This sample includes a ASP.Net Core 2.0 api that returns a Guid unique to the instance of the app.
Controller
using Microsoft.AspNetCore.Mvc;
using System;
namespace MinimalDockerTest.Controllers {
[Route("api/[controller]")]
public class NodeController : Controller {
[HttpGet]
public IActionResult Get() {
return Ok(NodeId);
}
private static Guid NodeId {
get;
} = Guid.NewGuid();
}
}
Dockerfile
#Context is binary output folder, i.e. bin/publishoutput
FROM microsoft/aspnetcore:2.0-nanoserver-sac2016
EXPOSE 80
WORKDIR /app
Copy . .
ENTRYPOINT ["dotnet", "MinimalDockerTest.dll"]
Build Command
docker build -t minimaltest .
Run Command
docker run -p 80:80 --name minimaltest minimaltest
Service Command
docker service create -p 80:80 --replicas 5 --name minimaltest minimaltest
Request
GET: http://node_ip/api/node
System
Edit
Found some good info here on SO.
I beleive you need to publish port in "host" mode (learn.microsoft.com/en-us/virtualization/windowscontainers/…). Also it will be one to one port mapping between running container and host and hence you will not be able to run several containers on the same port. Routing mesh is not working on Windows yet.
Now the question remains; When will mesh routing be supported?
Apparently mesh routing is not available for Windows 10 Version 1703. Mesh Routing was made the default option on Windows with version 1709.