Alberto
Alberto

Reputation: 12949

Docker containers unable to comunicate

I have 2 containers that belongs to the same network:

version: '3'
services:
  #PHP Service
  app:
    build:
      context: ./website
      dockerfile: Dockerfile
    image: travellist
    container_name: app
    restart: unless-stopped
    depends_on:
      - db
    tty: true
    ...
    networks:
      - app-network

  administration:
    build:
      dockerfile: Dockerfile
    image: travellist
    container_name: administration
    restart: unless-stopped
    depends_on:
      - db
    tty: true
    environment:
      ....
    networks:
      - app-network

  #Nginx Service
  webserver:
    container_name: webserver
    image: nginx:1.17-alpine
    restart: unless-stopped
    depends_on:
      - db
    ports:
      - 8000:80
      - 7999:81
    ...
    networks:
      - app-network

#Docker Networks
networks:
  app-network:
    driver: bridge

as you can see the two applications runs over NGINX over 2 different ports... however, I'm unable to send a request from one application to the other one... non of the following works (from administration, that is the one that works over 81:7999):

localhost:80
localhost:8000
app:80
app:8000

Upvotes: 0

Views: 53

Answers (1)

Eugenio Carocci
Eugenio Carocci

Reputation: 161

From the administration container you should send your request to the webserver on port 80.

From the administration container, you can first check that you can ping the webserver, if it succeeds it means that the two can reach each other on the network and for this reason, you can execute your request.

Please note that the port 8000 is only exposed to the host machine.

Upvotes: 1

Related Questions