I am trying to map a port when I debug a local container. From the commandline I would add -p 8883:8883 to the commandline. How do I set this when using the container tools?
I've tried to add
to me csproj, but it's not working.
@hannesne How you add this would depend on the project type and if the port is for HTTP/HTTPS communication. Can you share your Dockerfile, project file, and PropertieslaunchSettings.json?
Assuming that you're describing a single project scenario and not Docker Compose or Service Fabric, then in the typical case your PropertieslaunchSettings.json file contains the port mapping values for http and https, like so:
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/values",
"httpPort": 10003,
"useSSL": true,
"sslPort": 44382
}
httpPort specifies the host port that's mapped to port 80 in the container. sslPort specifies the host port that's mapped to port 443 in the container.
In your case, though, it looks like you want to map a host port to port 8883 in the container. To do that you would add a property to your csproj like so:
<PropertyGroup>
<DockerfileRunArguments>-p 8883:8883</DockerfileRunArguments>
</PropertyGroup>
And, finally, ensure that you're referencing the latest Microsoft.VisualStudio.Azure.Containers.Tools.Targets NuGet package to get all the latest bug fixes.
One addendum: The above just describes how to get docker to map the host port to a particular container port. If you want something (e.g. Kestrel) to actually listen on port 8883, additional work is involved.
Cool thanks, I'll give that a try. It's for communication on a TCP socket, so the project file should work. Can I suggest we change the launchsettings port mapping to accept an array of "port:port" settings for port mapping?
I'll second @hannesne. It's pretty painful to get VS to map the correct ports if you aren't running on 80 or 443 (which is best practice to avoid if you aren't running as root on linux containers, since ports < 1024 require superuser). This seems like a concern for the launchSettings.json file.
What are the steps required for VS to listen to another port (besides 80 or 443) ?
Wouldn't this be the ASPNETCORE_URLS environmental setting?
Most helpful comment
Assuming that you're describing a single project scenario and not Docker Compose or Service Fabric, then in the typical case your PropertieslaunchSettings.json file contains the port mapping values for http and https, like so:
httpPort specifies the host port that's mapped to port 80 in the container. sslPort specifies the host port that's mapped to port 443 in the container.
In your case, though, it looks like you want to map a host port to port 8883 in the container. To do that you would add a property to your csproj like so:
And, finally, ensure that you're referencing the latest Microsoft.VisualStudio.Azure.Containers.Tools.Targets NuGet package to get all the latest bug fixes.