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
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 likeports: ['<your_port>:8080']
.Check anycable configuration page (contains env variables info): https://docs.anycable.io/#/anycable-go/configuration
You need to setup anycable-rails by adding anycable-rails gem to your Gemfile:
when using Redis broadcast adapter
(and don’t forget to run bundle install).
Then, run the interactive configuration wizard via Rails generators:
Configuration
Next, update your Action Cable configuration:
Install WebSocket server and specify its URL in the configuration:
For development it’s likely the localhost
For production it’s likely to have a sub-domain and secure connection
Now you can start AnyCable RPC server for your application:
Don’t forget to provide Rails env in production
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:
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):