Reputation: 148704
Last thing first :
I want to run 2 Asp.net core apps and to be able to call each (via different port).
http://localhost:3333/api/values // for webapplication3
http://localhost:5555/api/values // for webapplication1
I've managed to do it partially - but it seems that only one is active at a time.
This is the dockerfile for webapplication3
( in webapplication3 folder)
FROM microsoft/dotnet:latest WORKDIR /app ADD ./bin/Debug/netcoreapp2.1 /app EXPOSE 80 CMD ["dotnet", "WebApplication3.dll"]
This is the dockerfile for webapplication1
( in webapplication1 folder)
FROM microsoft/dotnet:latest WORKDIR /app ADD ./bin/Debug/netcoreapp2.1 /app EXPOSE 80 CMD ["dotnet", "WebApplication1.dll"]
The Docker-compose.yml
file :
version: '3.4' services: webapplication3: image: microsoft/dotnet:latest build: ./WebApplication3 ports: - "3333:80" webapplication1: image: microsoft/dotnet:latest build: ./WebApplication1 ports: - "5555:80"
Great let's build & up :
As you can see both are ON :
Let's see docker ps
:
Now let's try to invoke :
As you can see both are working BUT I should've get DIFFERENT result !
(I've modified the actions to return different results )
I'm expecting that
http://localhost:3333/api/values
will show I'm response from webapplication 1
And
http://localhost:5555/api/values
will show I'm response from webapplication 3
As the YML file is configured
Question:
How can I make each endpoint to be accessed by the ports i've declared in docker-compose
?
Upvotes: 2
Views: 1268
Reputation: 148704
What the hell....
I've figured out what was my problem.
I will explain how I got to this answer.
At first I said to myself : "Forget the yml" , let's run it manually.
go to webapplication 1 folder ---->
docker run -p 5555:80 -d 3f10b9720b26
go to webapplication 3 folder ---->
docker run -p 3333:80 -d 3f10b9720b26
And still I GOT same result !
So it's not about yml
Then I thought , "I'm overriding the same image again and again , what if I tag each one differently ?"
So i've modified the yml to actually work with the image AND ADD A TAG : (which basically creates two different images)
version: '3.4'
services:
webapplication3:
image: microsoft/dotnet:foo
build: ./WebApplication3
ports:
- "3333:80"
depends_on:
- webapplication1
webapplication1:
image: microsoft/dotnet:bar
build: ./WebApplication1
ports:
- "5555:80"
And now ..........
Solved.
Do not run
on the same image again and again. use tags.
Upvotes: 2
Reputation: 1216
It's hard to give a definitive answer, because the problems might well be outside of the information your question supplies. But I can try to give you some trouble shooting tips:
docker-compose up -d
(as you probably already did)docker-compose ps
docker stop webapplication1
Can you still access both ports?
As you can see both are working BUT both go to the same service !
Are 100% sure this is really the case?
Upvotes: 0