How to access a website running on docker after closing the debug on Visual Studio

Viewed 1079

I build a very simple web app and web api on .net core and configured the docker-compose to get them to communicate over the same network correctly.

On visual studio, when I hit play on the Docker Compose project, it runs fine, both the web app and the web api work and communicate correctly.

On the Docker Desktop app i see them running (green). enter image description here

But when I close/stop the debugger on VS I can't access the websites anymore even though the containers are still running. I thought docker worked as a sort of IIS.

Am I misunderstanding the docker capabilities or do I need to run them again from a CLI or publish them somewhere or what? I thought the fact the containers are up and running should mean they're live for me to navigate to.

Help me out over here please.

1 Answers

You are correct, unless there is some special routing happening, the fact that the containers are running means your services are available.

You can see the ports being exposed from the docker ps -a command:

CONTAINER_ID: 560f78689902 
IMAGE: moviedecisionweb:dev 
COMMAND: "C:\\remote_debugger\\…"
CREATED: About a minute ago
STATUS: Up About a minute 
PORTS: 0.0.0.0:52002->80/tcp, 0.0.0.0:52001->443/tcp 
NAMES: mdweb

CONTAINER_ID: 1cd7f72426fe
IMAGE: moviedecisionapi:dev
COMMAND: "C:\\remote_debugger\\…"
CREATED: About a minute ago
STATUS: Up About a minute
PORTS: 0.0.0.0:52005->80/tcp, 0.0.0.0:52004->443/tcp
NAMES: mdapi

Based on the provided output, you have two docker containers running.

I'm assuming the ports 80 & 443 are serving the HTTP & HTTPS services (respectively) from your app/s.

Based on this...

For container "mdweb", you should be able to access the docker services from your docker host machine (PC) via:

For container "mdapi", you should be able to access the docker services from your docker host machine (PC) via:

I believe you can use localhost, 127.0.0.1 & 0.0.0.0 interchangeably in the above.

You cannot use the hostnames "mdweb" or "mdapi" from your docker HOST machine - unless you have explicitly setup your DNS to handle these names. However you can use these hostnames if you are inside a docker container on the same docker network.

If you provide more information (e.g. your docker-compose.yml), we could help you further...

Related