Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Laravel Sail with multiple docker-compose.yml files

Hello,

I'm new with Sail and Docker.

I have a Laravel application which works fine with docker and sail. The docker-compose.yml file declares several services like the database, laravel, rabbitmq, ...

Now I need to add in the same sail network an external JS application, I can easily dockerize this JS application. But this JS application depends on services from the Laravel Sail application. So how to declare the dependencies from another docker-compose.yml file ? Is it possible ?

Furthermore my problem is that it has to run in the same network as the sail network for Laravel.

Is it possible to execute sail up and then build the JS application separately so that it runs also in the sail network ? Perhaps a configuration to add in the docker-compose.yml for the JS application ?

Or perhaps it's impossible to do that ?

Thanks for your help.

V

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

Hello V,

Yes, it is possible to have multiple docker-compose.yml files and have services in them communicate with each other as long as they are on the same network. Laravel Sail uses Docker Compose under the hood, so you can leverage Docker Compose's networking features to achieve this.

Here's what you can do:

  1. Ensure that your Laravel Sail application and your external JS application are on the same Docker network. You can define a network in your Laravel application's docker-compose.yml and then reference that network in your JS application's docker-compose.yml.

  2. In your Laravel application's docker-compose.yml, define a network at the bottom of the file:

networks:
  sail:
    driver: bridge
  1. In the service definitions in your Laravel docker-compose.yml, make sure to connect each service to the defined network:
services:
  laravel.test:
    # ... other configuration ...
    networks:
      - sail
  # ... other services ...
  1. In your JS application's docker-compose.yml, reference the same network. You don't need to redefine the network, just make sure the name matches and that it's marked as external:
services:
  js-app:
    # ... other configuration ...
    networks:
      - sail

networks:
  sail:
    external: true
  1. Now, when you run sail up for your Laravel application, it will create the network if it doesn't already exist. Then, when you run docker-compose up for your JS application, Docker Compose will attach the JS application's containers to the existing sail network.

  2. To ensure that your JS application can communicate with the services in the Laravel application, use the service names defined in the Laravel docker-compose.yml as hostnames. For example, if you want to connect to the database from your JS application, you would use the service name of the database as the hostname.

Remember that you need to start the Laravel Sail environment first to ensure the network is created before you start your JS application. Also, make sure that the service names are unique across both docker-compose.yml files to avoid any conflicts.

By following these steps, you should be able to have both your Laravel application and your external JS application running in the same network and communicating with each other as needed.

I hope this helps! Let me know if you have any further questions.

1 like

Please or to participate in this conversation.