-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How-to use Dev Proxy with apps running in a Docker container #427
Comments
Usage with proxy running on the host and the app in a container is covered here: https://learn.microsoft.com/en-us/microsoft-cloud/dev/dev-proxy/how-to/use-dev-proxy-with-dotnet-docker?pivots=client-operating-system-windows |
I spent the last few days getting dev-proxy working in a docker compose setup, with one container calling through dev-proxy. Leaving this here for anyone else who finds their way here with Google. The steps:
Graph.Dockerfile to build dev-proxy container FROM mcr.microsoft.com/dotnet/runtime-deps:8.0 AS setup
RUN apt -y update
RUN apt -y upgrade
RUN apt install -y curl unzip
USER app
WORKDIR /home/app
RUN curl -sL https://aka.ms/devproxy/setup.sh | bash
RUN /home/app/devproxy/devproxy msgraphdb
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0 AS run
WORKDIR /home/app
USER app
COPY --from=setup /home/app/devproxy ./
CMD ["./devproxy", "--ip-address", "0.0.0.0", "--port", "80", "--config-file", "presets/m365.json", "--failure-rate", "0", "--install-cert"] entrypoint.sh, in my dotnet app's container #!/bin/bash
set -e
if ! test -f /usr/local/share/ca-certificates/dev-proxy-ca.crt; then
openssl pkcs12 -in tls/rootCert.pfx -out /usr/local/share/ca-certificates/dev-proxy-ca.crt -nodes -password pass:
update-ca-certificates
fi
exec dotnet "$@" docker-compose overrides to add dev-proxy container and proxy though it services:
graph:
build:
dockerfile: Graph.Dockerfile
expose:
- 80
stdin_open: true
tty: true
volumes:
- tls:/home/app/dev-proxy
api:
build:
target: dev
environment:
HTTPS_PROXY: http://graph
HTTP_PROXY: http://graph
depends_on:
- graph
volumes:
- tls:/home/app/tls:ro
volumes:
tls: |
This is awesome! Thank you so much for sharing! We'll look for ways to get it added to our docs for easier discovery |
@kirkedev thanks for this, can you tell me how did you arrive at
this configuration. I don't fully understand how the packets are getting proxied from one container to another. |
@prakashnathjha Those are environment variables that dotnet's HttpClient will use as a default, application level proxy. They're more or less a standard by convention. A lot of other environments will use those too. In the docker compose file they're pointing at the graph service, which is my dev proxy. https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.defaultproxy?view=net-8.0 |
Hey @kirkedev , thanks for the explanation. I was actually more confused about |
Add a how to article that explains how to use Dev Proxy with apps running in a Docker container. Include two scenarios:
The text was updated successfully, but these errors were encountered: