Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 362
simple-thomas Avatar asked Aug 17 '20 09:08

simple-thomas


People also ask

How to debug apps in a local Docker container?

To debug apps in a local Docker container, the following tools must be installed: Visual Studio 2019 with the Web Development workload installed To run Docker containers locally, you must have a local Docker client. You can use Docker for Windows, which uses Hyper-V and requires Windows 10.

Does Visual Visual Studio work with Docker containers?

Visual Studio has excellent built in support for working with Docker containers, and most of the examples on the web are written with those tools installed. But what about the situation where the container is already running?

How do I debug Docker in Visual Studio 2017?

To start debugging and hit the breakpoint, press F5. Switch to Visual Studio to view the breakpoint. Inspect values. When you use .NET Framework console app projects, the option to add Docker support without orchestration isn't supported.

What happens when you run Docker container?

After entering the command, Docker will download the repository image (unless it has already been downloaded locally) and then run the container. The difference this time is that the web server process is started and because it has not exited, the container is still running.


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:

  • http://0.0.0.0:52002
  • https://0.0.0.0:52001

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

  • http://0.0.0.0:52005
  • https://0.0.0.0:52004

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...

like image 104
Nick Grealy Avatar answered Nov 15 '22 08:11

Nick Grealy