0

I was looking for, On how i can call other container from other docker-compose.yaml. And my research i was able to get and idea, In order to communicate i must implement "user-defined bridge network". For past years they use "links" buts its deprecated now.

Reference link: https://www.tutorialworks.com/container-networking/

After the implementation both docker-compose.yaml has same network.

The Question is how do i call the other container from other compose?

I would like to ask for your recommendation of any sample project or Guide/Tutorial to read.

//Project 2
//I want project 2 communicate with Project 1 and use their port
//docker-compose.yaml

version: '3.8'

networks:
  default:
    name: product-poc-project-net
    external: true

services:
  loggermicroservice:
    image: loggermicroservice
    container_name: loggermicroservice
    build:
     context: ./
     dockerfile: Dockerfile
    depends_on:
      - mongodb
      
   
    
   
 #----------------------------------------------------------------     
  mongodb:
    image: mongo:latest
    container_name: mongodb
    restart: unless-stopped
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_DATABASE: LoggerActivity
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: root
    volumes:
      - ./database-data:/data/db
#----------------------------------------------------------------   
  mongo-express:
    image: mongo-express:latest
    container_name: mongo-express 
    restart: unless-stopped
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: root
      ME_CONFIG_MONGODB_SERVER: mongodb
      ME_CONFIG_MONGODB_PORT: 27017
            



    



//Project1
//I want kafka and zookeeper container be used in Project 2

version: '3.8'

networks:
  default:
    name: product-poc-project-net
    external: true
    
services: 
#----------------------------------------------------------------  
  productmicroservice:
    image: productmicroservice:latest
    container_name: productmicroservice
    depends_on:
      - product-mysqldb
      - kafka
    restart: always
    build:
      context: ./
      dockerfile: Dockerfile
    ports:
      - "9001:8091"
    
    environment:
    
      - MYSQL_HOST=product-mysqldb
      - MYSQL_USER=oot
      - MYSQL_PASSWORD=root
      - MYSQL_PORT=3306
      
      - "SPRING_PROFILES_ACTIVE=${ACTIVE_PROFILE}"
    
      
    
#----------------------------------------------------------------      

  product-mysqldb:
    image: mysql:8.0.28
    restart: unless-stopped
    container_name: product-mysqldb
    ports: 
      - "3307:3306"
    
    cap_add:
      - SYS_NICE
    environment:
      MYSQL_DATABASE: dbpoc
      MYSQL_ROOT_PASSWORD: root
    
      
#----------------------------------------------------------------   

        
  zookeeper:
    image: elevy/zookeeper:latest
    container_name: zookeeper
    ports:
      - "2181:2181"
   
     
    
      
      
#----------------------------------------------------------------
 
    
  kafka:
    image: wurstmeister/kafka:2.11-2.0.0
    container_name: kafka
    
    restart: on-failure

    ports:
      - "9092:9092"
      - "9093:9093"
      
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_CREATE_TOPICS: "producttopic:1:1"
      
      KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
      KAFKA_LISTENERS: INSIDE://kafka:9092,OUTSIDE://0.0.0.0:9093
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:9092,OUTSIDE://localhost:9093
    depends_on:
      - zookeeper
    
          
  
  • 1
    What you show should work; the important thing is that the `default` network in one of the Compose files is configured as `external: true` with a `name:` matching the `default` network of the other (setting them both to the same manually-created network as you have it works too). – David Maze May 07 '22 at 11:41

0 Answers0