skip to Main Content

How can i setup anycable(action cable) port on docker?

this is my Dockerfile for anycable

FROM ruby:2.6.3-alpine3.10

WORKDIR /home/app

COPY . /home/app/

EXPOSE 50051

CMD ["anycable"]

and this is my docker-compose

version: "3"
services:
  app:
    build:
      context: .
      dockerfile: ./dockers/app/Dockerfile
    container_name: out_app
    restart: unless-stopped
    volumes:
      - .:/app
      - /app/node_modules
      - /app/public/assets
      - /app/public/packs
    ports:
      - 3000:3000
  db:
    build:
      context: .
      dockerfile: ./dockers/postgis/Dockerfile
    container_name: out_db
    environment:
      POSTGRES_USER: ${DOCKER_DB_USER}
      POSTGRES_PASSWORD: ${DOCKER_DB_PASSWORD}
      POSTGRES_DB: ${DOCKER_DB_NAME}
    volumes:
      - /docker_data/giggle/postgres:/var/lib/postgresql/data
    ports:
      - 5435:5432
  nginx:
    build:
      context: .
      dockerfile: ./dockers/web/Dockerfile
    container_name: out_web
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
    depends_on:
      - app
    volumes:
      - ./dockers/web/nginx.conf:/etc/nginx/conf.d/default.conf
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
  certbot:
    image: certbot/certbot
    restart: unless-stopped
    volumes:
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
  redis:
    image: redis
    volumes:
      - ../../tmp/db:/var/lib/redis/data
  delayed_job:
    build:
      context: .
      dockerfile: ./dockers/delayed_job/Dockerfile
    container_name: out_delayed_job
    command: bundle exec rails jobs:work
    depends_on:
      - db
    volumes:
      - .:/app
  # anycable:
  #   image: 'anycable/anycable-go:edge-mrb'
  #   ports:
  #     - "3334"
  #   environment:
  #     ANYCABLE_HOST: 0.0.0.0
  #     REDIS_URL: redis://redis:6379/1
  #     ANYCABLE_RPC_HOST: 0.0.0.0:3334
  #     ANYCABLE_DEBUG: 1
  #   command: bundle exec anycable
  anycable:
    build:
      context: .
      dockerfile: ./dockers/anycable/Dockerfile
    container_name: anycable
    command: bundle exec anycable
    depends_on:
      - redis

2

Answers


  1. You provided anycable-go configuration. To set custom port for anycable-go server add ANYCABLE_PORT: <your port> to anycable-go image environment or expose image port like ports: ['<your_port>:8080'].

    Check anycable configuration page (contains env variables info): https://docs.anycable.io/#/anycable-go/configuration

    Login or Signup to reply.
  2. You need to setup anycable-rails by adding anycable-rails gem to your Gemfile:

    gem "anycable-rails", "~> 1.1"
    

    when using Redis broadcast adapter

    gem "redis", ">= 4.0"
    

    (and don’t forget to run bundle install).

    Then, run the interactive configuration wizard via Rails generators:

    bundle exec rails g anycable:setup
    

    Configuration
    Next, update your Action Cable configuration:

    # config/cable.yml
    production:
      # Set adapter to any_cable to activate AnyCable
      adapter: any_cable
    

    Install WebSocket server and specify its URL in the configuration:

    For development it’s likely the localhost

    # config/environments/development.rb
    config.action_cable.url = "ws://localhost:8080/cable"
    

    For production it’s likely to have a sub-domain and secure connection

    # config/environments/production.rb
    config.action_cable.url = "wss://ws.example.com/cable"
    

    Now you can start AnyCable RPC server for your application:

    $ bundle exec anycable
    #> Starting AnyCable gRPC server (pid: 48111)
    #> Serving Rails application from ./config/environment.rb
    

    Don’t forget to provide Rails env in production

    $ RAILS_ENV=production bundle exec anycable
    

    NOTE: you don’t need to specify `-r option (see CLI docs), your application would be loaded from config/environment.rb.

    And, finally, run AnyCable WebSocket server, e.g. anycable-go:

    $ anycable-go --host=localhost --port=8080
    

    INFO 2019-08-07T16:37:46.387Z context=main Starting AnyCable v0.6.2-13-gd421927 (with mruby 1.2.0 (2015-11-17)) (pid: 1362)
    INFO 2019-08-07T16:37:46.387Z context=main Handle WebSocket connections at /cable
    INFO 2019-08-07T16:37:46.388Z context=http Starting HTTP server at localhost:8080

    You can store AnyCable-specific configuration in YAML file (similar to Action Cable one):

    # config/anycable.yml
    development:
      redis_url: redis://localhost:6379/1
    production:
      redis_url: redis://my.redis.io:6379/1
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search