docker-angular-dotnet app
I do mostly backend dev and I don't want to build my angular app every time. I wanted to host it in my local docker hub and run it. But I'm able to see the login page but it looks like it's not able to invoke the backend apis. The config in the angular app is pointing to localhost, I tried changing it to use the ngrok to ensure that it points the dotnet API on the host machine but nothing worked, any idea what went wrong?
5 Replies
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
I want to run the backend on host machine that is my local machine
And FE on the docker
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
localhost
has a different meaning for the containerized angular app. It will look for the api inside the same container. It has no idea you are referring to the host running the container.
To achieve what you want, docker has a few special variables, such as host.docker.internal
and gateway.docker.internal
. For docker run
you would use the --add-host=host.docker.internal:my-api
switch and then point your angular app at my-api
instead of localhost
. Alternatively you could hard code your local pc IP address, but it probably is dynamic, and you probably would need to configure the DNS resolver for the container to use.
For more info simply google those keywords.
If you run the api in a second container, as @TeBeCo suggests, you can use a docker-compose file to bring them both up and either create an explicit network or let docker-compose do its magic and your api address will be the same name as the service under which the api is defined in the yaml file.Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View