I have created two networks in podman, "backend" and "frontend".
NAME VERSION PLUGINS
podman 0.4.0 bridge,portmap,firewall,tuning
backend 0.4.0 bridge,portmap,firewall,dnsname
frontend 0.4.0 bridge,portmap,firewall,dnsname
I have a MS Sql Server container running in "backend" network using the following command:
podman run -d -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=TestS01Pass' --name mssqlserver -v sqlvolume:/var/opt/mssql --network backend mcr.microsoft.com/mssql/server:2019-latest
I also have three .netcore web apps (productapp1, productapp2, productapp3) which are assigned to both "backend" and "frontend" networks. Please see below the content of the dockerfile for them:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
COPY dist /app
WORKDIR /app
EXPOSE 80/tcp
ENTRYPOINT [ "dotnet", "DockerSample.dll" ]
And these are the commands I've used to create them:
podman create --name productapp1 --network backend,frontend docker-sample
podman create --name productapp2 --network backend,frontend docker-sample
podman create --name productapp3 --network backend,frontend docker-sample
I also have an haproxy container that's assigned to the "frontend" network using the following command:
podman run -d --name loadbalancer --network frontend --volume $(pwd)/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg -p 3000:80 --privileged haproxy:latest
The configuration for haproxy is as follows:
defaults
timeout connect 5000
timeout client 50000
timeout server 50000
frontend localnodes
bind *:80
mode http
default_backend mvc
stats enable
stats uri /stats
stats refresh 1s
backend mvc
mode http
balance roundrobin
server mvc1 productapp1:80
server mvc2 productapp2:80
server mvc3 productapp3:80
By looking at logs for web apps, I can confirm that they're working as expected without any problem. Please see below the logs for one of the web app containers:
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
Applying Migrations...
Seed Data Not Required...
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
The problem is when I navigate to http://localhost:3000, I receive the 503 Service Unavailable message. (No server is available to handle this request.)
I ran the following command on one of webapps and verified the port for mssqlserver is accessible:
podman exec -it productapp1 /bin/nc -zvw3 mssqlserver 1433
The result is:
DNS fwd/rev mismatch: mssqlserver != mssqlserver.dns.podman
mssqlserver [10.89.1.55] 1433 (?) open
But if I run the same command for one of web apps:
podman exec -it productapp1 /bin/nc -zvw3 productapp2 80
podman exec -it productapp1 /bin/nc -zvw3 productapp2 5000
Both returns the connection refused message:
DNS fwd/rev mismatch: productapp2 != productapp2.dns.podman
productapp2 [10.89.1.57] 80 (?) : Connection refused
DNS fwd/rev mismatch: productapp2 != productapp2.dns.podman
productapp2 [10.89.1.57] 5000 (?) : Connection refused
I wonder if anyone could shed a light on this as I've been searching and reading a lot and yet can't figure out why something this simple shouldn't work.
Really appreciated.
Thanks.
Update 1: I forgot to mention that I have tried haproxy with the following configuration too:
defaults
timeout connect 5000
timeout client 50000
timeout server 50000
frontend localnodes
bind *:80
mode http
default_backend mvc
stats enable
stats uri /stats
stats refresh 1s
backend mvc
mode http
balance roundrobin
server mvc1 productapp1:5000
server mvc2 productapp2:5000
server mvc3 productapp3:5000
Update 2: The following is the content of my launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:30113",
"sslPort": 44371
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"DockerSample": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
I also tried creating the containers with -e ASPNETCORE_URLS=http://+:5000 but still I'm getting the same error.
Update 3: Updated launchSettings.json to:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:30113",
"sslPort": 44371
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"DockerSample": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://+:5001;http://+:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Update 4: After helps from Michael Hampton, I managed to get the port 5000 open for my web app containers. The logs for my web app containers look like this now:
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
I can also netcat this port from other containers:
DNS fwd/rev mismatch: productapp2 != productapp2.dns.podman
productapp2 [10.89.1.82] 5000 (?) open
And I can now navigate to my web apps as expected.