DEV Community

Krixnaas
Krixnaas

Posted on

2 2

Multiple Laravel Application to Communicate in Docker Container

version: '3'
services:
  app1_server:
    container_name : "app1_server"
    image : "app1_server"
    build :
      context : "app1"
    ports:
      - 8099:80
    volumes:
      - "./app1:/var/www/app1"
    networks:
      net:
        ipv4_address: 10.5.0.5
  app2_server:
    container_name : "app2_server"
    image : "app2_server"
    build :
      context : "app2"
    ports:
      - 8098:80
    volumes:
      - "./app2:/var/www/app2"
    expose:
      - "80"
    networks:
      net:
        ipv4_address: 10.5.0.6
networks:
  net:
    driver: bridge
    ipam:
     config:
       - subnet: 10.5.0.0/16
         gateway: 10.5.0.1
Enter fullscreen mode Exit fullscreen mode

Now you can call from app2 from app1.

For example create test api on app2

Route::get('/api/test', function(){
    return "okay";
});
Enter fullscreen mode Exit fullscreen mode

and create route on app1:

Route::get('test', function(){   
    $response =  Http::withHeaders([
        'Content-Type' => 'charset=UTF8'
    ])->send('get', 'http://10.5.0.6:80/api/test');
    return $response;
});
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay