Royi Namir
Royi Namir

Reputation: 148704

Docker-compose runs 2 containers , but only one service is working?

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 :

enter image description here

As you can see both are ON :

Let's see docker ps :

enter image description here

Now let's try to invoke :

enter image description here

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

Answers (2)

Royi Namir
Royi Namir

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

enter image description here

And still I GOT same result !

enter image description here

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)

enter image description here

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

enter image description here

Solved.

Do not run on the same image again and again. use tags.

Upvotes: 2

hjsimpson
hjsimpson

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:

  1. Start your services with docker-compose up -d(as you probably already did)
  2. check status and port forwards with docker-compose ps
  3. Do your api checks
  4. Stop one service with docker stop webapplication1
  5. Repeat 2. & 3.

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

Related Questions