My workplace has a docker-compose file with its own network and dozens of services. It represents the fundamental behaviour of our distributed application, and I can't change it.
I wanted to experiment with Aspire at work to host our team's infrastructure and I wondered if it was possible for them to communicate in the way I needed.
In short, it is.
This prototype demonstrates how an Aspire run service, or Docker container, can hit a Docker container run in parallel with docker-compose.

Step 1a: The consumer can either call /direct-request
, which is intended for the web project to try to call http://barservice.colin
directly.
Step 1b: Or it can call /via-container
, which calls a mockservice
container for it to proxy to http://barservice.colin
instead.
The hosts file of the development environment points http://barservice.com
to itself.
This NGINX container has been run via the docker-compose.yaml
file, and shares a network with another mockserver container.
If called with /foo
it returns a 201 (if the web service hit it directly).
If called with /bar
it returns a 202 (via the proxy container in Aspire)
There are integration tests that confirm that Created/201 and Accepted/202 are correctly returned by the web service.
In order for them to be run successfully, or to run Aspire yourself, follow these steps:
- Make sure your hosts file is set up to route requests for
barservice.colin
, see below for instructions - Docker compose up the
/docker-compose/docker-compose.yaml
file - Run the Aspire orchestration
ColinCCook.AppHost.AppHost
, or, build and run the unit tests.
-
Open Terminal
-
Edit the hosts file using nano (recommended for beginners):
sudo nano /etc/hosts
-
Add this line at the end of the file:
127.0.0.1 barservice.colin
-
Save and exit:
- Press
Ctrl+X
, thenY
, thenEnter
- Press
-
Flush DNS cache:
sudo dscacheutil -flushcache sudo killall -HUP mDNSResponder
-
Verify the entry was added. It should output the line you've just added:
cat /etc/hosts | grep barservice.colin
-
Open Command Prompt as Administrator:
- Press
Win + X
and select "Command Prompt (Admin)" or "Windows PowerShell (Admin)" - Or search for "cmd" in Start menu, right-click and select "Run as administrator"
- Press
-
Edit the hosts file using notepad:
notepad C:\Windows\System32\drivers\etc\hosts
-
Add this line at the end of the file:
127.0.0.1 barservice.colin
-
Save and exit:
- Press
Ctrl+S
to save - Close Notepad
- Press
-
Flush DNS cache:
ipconfig /flushdns
-
Verify the entry was added:
findstr "barservice.colin" C:\Windows\System32\drivers\etc\hosts