Running ASP.NET Core in a container on a custom port in App Services

November 1, 2019

I wanted to see if I could get Azure Web App on Containers working on a custom port. It turns out you can but you can't expose the container on anything other than port 80 or 443.  

I tried this out locally first with ASP.NET Core. Taking the sample, and changing the port of the web server inside the image to be 8000....


docker run --rm -it -p 8000:8000 -e ASPNETCORE_URLS="http://*:8000"


The environment variable, ASPNETCORE_URLS, needs to be passed in matching any ip in the container to port 8000. I'm mapping port 8000 on my host to that of the container's process.

The documentation for Web App on Containers states you need to add environment variables to the Application Settings under Configuration but it also advises that to run on a custom port WEBSITES_PORT setting is required. Slightly confusing is that when you set this and view the Container Settings blade you don't see the environment variable on the docker run statement....

docker run -d -p 53967:8000 --name mccontainer_0_a97e8f2d -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=8000 -e WEBSITE_SITE_NAME=mccontainer -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e -e WEBSITE_INSTANCE_ID=57008eb873c7365c6ef907311d1d26e719d2d304effbc14458cd2f45247bca14

But you do need both settings and it does work (I had to wait for several minutes for my container to pick up a change in the settings). When I navigate to my containerised website is loaded.



Share on Facebook
Share on Twitter
Please reload

Featured Posts

I'm busy working on my blog posts. Watch this space!

Please reload

Recent Posts

November 14, 2017

Please reload

Search By Tags
Please reload

  • Google+ Social Icon
  • Facebook Social Icon
  • LinkedIn Social Icon
  • Twitter Social Icon

Contact Me

  • LinkedIn Social Icon
  • Twitter Social Icon

© 2017 Matt Cowen

Wiltshire, UK