Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I ensure the WebSocket server port is correctly exposed in Docker
    Docker WebSocket Laravel Pusher Docker Compose WebSocket configuration Laravel WebSockets Docker setup


How do I ensure the WebSocket server port is correctly exposed in Docker


To ensure the WebSocket server port is correctly exposed in Docker, follow these steps:

Step 1: Configure the Docker Compose File

1. Expose the Port:
- In your `docker-compose.yml` file, add the following lines to expose the WebSocket server port:
yaml
     services:
         websockets:
             image: beyondcode/laravel-websockets
             ports:
                 - "6001:6001"
     

Step 2: Configure the Laravel WebSockets Configuration

1. Update the Configuration:
- Ensure that the WebSocket server port is correctly set in your `websockets.php` file:
php
     'host' => env('LARAVEL_WEBSOCKETS_HOST', 'localhost'),
     'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
     

Step 3: Configure the Pusher Configuration

1. Update the Pusher Configuration:
- Ensure that the Pusher configuration is correctly set in your `broadcasting.php` file:
php
     'pusher' => [
         'driver' => 'pusher',
         'key' => env('PUSHER_APP_KEY'),
         'secret' => env('PUSHER_APP_SECRET'),
         'app_id' => env('PUSHER_APP_ID'),
         'options' => [
             'cluster' => env('PUSHER_APP_CLUSTER'),
             'encrypted' => true,
             'host' => env('LARAVEL_WEBSOCKETS_HOST'),
             'port' => env('LARAVEL_WEBSOCKETS_PORT'),
             'scheme' => 'http',
         ],
     ],
     

Step 4: Verify the WebSocket Connection

1. Verify WebSocket Connection:
- Use a tool like `wscat` to test the WebSocket connection:
bash
     wscat -c ws://localhost:6001
     

Step 5: Verify the Laravel Configuration

1. Verify Laravel Configuration:
- Ensure that the `BROADCAST_DRIVER` is set to `pusher` in your `.env` file:
bash
     BROADCAST_DRIVER=pusher
     

Step 6: Verify the Pusher Configuration

1. Verify Pusher Configuration:
- Ensure that the Pusher configuration is correctly set in your `.env` file:
bash
     PUSHER_APP_KEY=your_app_key
     PUSHER_APP_SECRET=your_app_secret
     PUSHER_APP_ID=your_app_id
     

By following these steps, you can ensure that the WebSocket server port is correctly exposed in Docker and that your Laravel application is configured to use the WebSocket server correctly.

Citations:
[1] https://github.com/laradock/laradock/issues/2002
[2] https://www.heondokim.com/articles/laravel-websockets-nginx-docker
[3] https://laracasts.com/discuss/channels/laravel/laravel-websocket-failed-to-connect-to-127001-port-6001-on-docker?reply=880224
[4] https://www.reddit.com/r/laravel/comments/nzjhmy/laravel_websockets_apache2_docker/?rdt=60559
[5] https://laravelgeek.com/posts/building-real-time-applications-with-laravel-websockets-a-comprehensive-guide