Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Problem with Docker #81

Closed
T0miii opened this issue Jan 10, 2019 · 15 comments
Closed

Problem with Docker #81

T0miii opened this issue Jan 10, 2019 · 15 comments

Comments

@T0miii
Copy link

T0miii commented Jan 10, 2019

Hello,

im trying to make Websocket work with my Dev Docker setup, but there is still some problem i cant figure out.
This is my docker-compose.yaml i start the Websocket Server in its own container its upp and running

  websocket:
    image: docker-registry.company.com/cx_dev_app:latest
    working_dir: /www/
    volumes:
      # Projects
      - ../vme/.:/www/vme
      - ./app/cron.d/.:/etc/my.cron.d
      - ./app/startup.sh:/startup.sh
      - ./app/websocket.sh:/websocket.sh

    command: ["sh", "-c", "php /www/vme/artisan websockets:serve --host=0.0.0.0"]
    ports:
      - "6001:6001"
    expose:
      - "6001"
    environment:
    depends_on:
      - app
    networks:
      app_net:
        ipv4_address: xxx.29.0.88

The Server is up and runing:
websocket_1 | Starting the WebSocket server on port 6001...

broadcasting.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'),
                'host' => 'websocket',
                'port' => 6001,
                'encrypted' => true,
                'scheme' => 'http'
            ],
        ],

and the bootstrap.js:

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'vme-key',
    wsHost: window.location.hostname,
    wsPort: 6001,
    disableStats: true,
});

When i refresh my page i get following error:
image

Sadly could not find anything similar to this Issue.

@MWL91
Copy link

MWL91 commented Feb 11, 2019

The same issue here, with docker.

I have those errors:

  • WebSocket connection to 'ws://localhost:6001/app/anyKey?protocol=7&client=js&version=4.3.1&flash=false' failed: Error in connection establishment: net::ERR_SOCKET_NOT_CONNECTED
  • pusher.min.js:8 WebSocket connection to 'ws://localhost:6001/app/anyKey?protocol=7&client=js&version=4.3.1&flash=false' failed: Connection closed before receiving a handshake response

Have you handle with it?

@T0miii
Copy link
Author

T0miii commented Feb 11, 2019

If i remember correctly we started the websocket on --host=0.0.0.0 also exposed the 6001 port in our docker-composer.yml file.

@edisonchenz
Copy link

The same issue here, with docker
How can I run laravel-websocket server with docekr

@MWL91
Copy link

MWL91 commented Feb 13, 2019

Hi, we handle it.
First, you have to setup port for this 6001 in docker.
Second, run server inside of docker bash.

You don't need any additional libraries ect.
If it's possible, share the errors with me - meaby i will help :)

@edisonchenz
Copy link

@MWL91
Hi, thank you
can you share me your docker-compose.yml for websocket
my error same with you

  • WebSocket connection to 'ws://localhost:6001/app/anyKey?protocol=7&client=js&version=4.3.1&flash=false' failed: Error in connection establishment: net::ERR_SOCKET_NOT_CONNECTED
  • pusher.min.js:8 WebSocket connection to 'ws://localhost:6001/app/anyKey?protocol=7&client=js&version=4.3.1&flash=false' failed: Connection closed before receiving a handshake response

thanks

@MWL91
Copy link

MWL91 commented Feb 14, 2019 via email

@anthonyvancauwenberghe
Copy link
Contributor

it would be amazing if this package comes with a docker container out of the box. And is maintained by the owners. Are there any plans for this? @freekmurze @mpociot

@francislavoie
Copy link
Contributor

francislavoie commented Jul 28, 2019

I can share my Dockerfile.

FROM php:7.3.3-alpine

RUN apk add --no-cache \
    wget \
    curl \
    git \
    shadow \
    build-base \
    autoconf \
    hiredis \
    libxml2-dev \
    zlib-dev \
    libevent \
    libevent-dev \
    openssl-dev \
    gmp-dev \
    icu-dev \
    && \
    docker-php-ext-install \
        pcntl \
        mbstring \
        pdo \
        pdo_mysql \
        tokenizer \
        xml \
        sockets \
        gmp \
        bcmath \
        intl \
        && \
    # Libevent
    pecl install event && \
    # phpiredis
    apk add --no-cache --virtual .build-deps \
        hiredis-dev \
        && \
    git clone https://github.com/francislavoie/phpiredis.git && \
    ( \
        cd phpiredis && \
        phpize && ./configure --enable-phpiredis && \
        make && make install && \
        docker-php-ext-enable phpiredis \
    ) && \
    rm -rf phpiredis && \
    # Cleanup
    apk del .build-deps && \
    rm -rf /var/cache/apk/* && \
    mkdir -p /var/www

RUN groupmod -g 1000 www-data && \
    usermod -u 1000 www-data

USER www-data

WORKDIR /var/www

EXPOSE 6001

CMD ["php", "artisan", "websockets:serve"]

You can probably strip out the phpiredis stuff, it's essentially a performance optimization when using Predis (which Laravel uses) but laravel-websockets doesn't use Predis, and #140 won't use Predis either because it uses the ReactPHP async Redis client instead. If you do end up needing it, I recommend configuring your config/database.php redis config with the following, which will make Predis use the phpiredis extension for better performance.

        'options' => [
            'connections' => [
                'tcp' => 'Predis\Connection\PhpiredisStreamConnection',
                'unix' => 'Predis\Connection\PhpiredisSocketConnection',
            ],
        ],

I made a fork because the phpiredis repo is inactive and is broken... I pulled in fixes from a few different pending PRs into my fork to make it work.

But anyways - all that is irrelevant, that Dockerfile should just work as-is. laravel-websockets has very few requirements to work well.

@joeloudjinz
Copy link

@francislavoie can you share the part of laravel websockets in docker-compose file, please.
Is it better to use it in a separate container?
I have configured the package in the same container of laravel app, first, the graph in the dashboard wasn't visible, I solved it by making perform_dns_lookup to true, but when I fire an event from tineker I don't see the trace of it in the dashboard.
i've tried several solutions like using the address IP of the container (or the name) besides using localhost (or 127.0.0.1)!

@francislavoie
Copy link
Contributor

francislavoie commented Sep 24, 2019

Sounds like you're running into #115

I prefer to run it in a separate container. I have these: caddy, websockets, php-fpm, horizon, db, redis and workspace (for general use CLI, artisan). Separation of concerns.

There's really nothing special to show in my docker-compose file, I just point to the Dockerfile to build, and share a volume for the code between containers.

@joeloudjinz
Copy link

@francislavoie I'm still getting the same issue, regardless that websockets container runs correctly, I get no traces in the dashboard when firing the event from tinker.
this is my dockerfile of websockets container:

FROM php:7.3.3-alpine
# FROM php:7.2-fpm

RUN apk add --no-cache \
    wget \
    curl \
    # git \
    shadow \
    build-base \
    autoconf \
    # hiredis \
    libxml2-dev \
    zlib-dev \
    libevent \
    libevent-dev \
    openssl-dev \
    gmp-dev \
    icu-dev

RUN docker-php-ext-install \
        pcntl \
        mbstring \
        pdo \
        pdo_mysql \
        tokenizer \
        xml \
        sockets \
        gmp \
        bcmath \
        intl

        # Libevent
RUN pecl install event

RUN apk update

# Cleanup
# apk del .build-deps && \
RUN rm -rf /var/cache/apk/* && \
    rm -rf /tmp/*

RUN mkdir -p /var/www

RUN groupmod -g 1000 www-data && \
    usermod -u 1000 www-data

USER www-data

WORKDIR /var/www/html

EXPOSE 6001

CMD ["php", "artisan", "websockets:serve"]

this is websockets service in docker-compoe

  ssms-sockets:
    build:
      context: ./docker/websockets
    container_name: ssms-sockets
    volumes:
      - .:/var/www/html
    ports:
      - 6001:6001
    networks:
      backend:
        aliases:
          - ssms-sockets

in the app container i'm exposing port 6001, and i'm setting the host to the name of the container:
PUSHER_APP_HOST=ssms-app

@oluseyianani
Copy link

@francislavoie can you share the part of laravel websockets in docker-compose file, please.
Is it better to use it in a separate container?
I have configured the package in the same container of laravel app, first, the graph in the dashboard wasn't visible, I solved it by making perform_dns_lookup to true, but when I fire an event from tineker I don't see the trace of it in the dashboard.
i've tried several solutions like using the address IP of the container (or the name) besides using localhost (or 127.0.0.1)!

I'm having this same problem. Were you able to resolve this? I'll like to know how you did, if you were. Thanks

@bunkerdevelopers
Copy link

greetings, I walk by here and I see that the last post, still persisted the problem, some will have solved it, I am in the same diatrive

@MWL91
Copy link

MWL91 commented Dec 3, 2020

I've started to use ratchet that allows to in-websocket interactions. The issue in my case was mismatch with events. Ratchet works also much faster.

@thallesdaniell
Copy link

thallesdaniell commented May 23, 2021

I was searching and when looking at documents, broadcast-queue there was the information that was going to the queue and when I looked at the jobs, everything was really going there. When I changed it solved for me. On my docker, I didn't have to expose the 6001.

My current configuration

Testing with the pusher.

BROADCAST_DRIVER=pusher
CACHE_DRIVER=database
QUEUE_CONNECTION=sync

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants