I have a rails app running through docker. I bring up the app with docker-compose (config below). The whole app covers a mysql, redis, rails (including sidekiq workers), nginx (with react frontend) and a rsyslog server, which forwards all logs to Loggly
My problem is realated to the logging part. Logs from all services basically gets forwarded, except from my logs from sidekiq.
When I start sidekiq with bundler exec sidekiq
the logs are output to the console (stdout), but I dont see them when I tail /var/log/messages on the rsyslog server.
I followed this tutorial when setting up the logging on docker:
https://medium.com/@yoanis_gil/logging-with-docker-part-1-b23ef1443aac
My thinking is that everything that goes to stdout in a docker container should be logged to the docker log mechanism - and with my setup that means it should go to the syslog server...
The docker-compose file:
version: '3'
services:
nginx:
image: nginx
depends_on:
- api
- syslog
ports:
- "80:8080"
logging:
driver: syslog
options:
syslog-facility: "daemon"
tag: "nginx"
syslog-address: "tcp://localhost:5514"
networks:
- phototankswarm
env_file: .env.dev
volumes:
- ./frontend/nginx/conf.d:/etc/nginx/conf.d
- ./frontend/public:/www
db:
image: mysql
env_file: .env.dev
depends_on:
- syslog
networks:
- phototankswarm
ports:
- "3306:3306"
volumes:
- ./backend/sql/data:/var/lib/mysql
logging:
driver: syslog
options:
syslog-facility: "daemon"
tag: "mysql"
syslog-address: "tcp://localhost:5514"
redis:
image: redis
depends_on:
- syslog
networks:
- phototankswarm
logging:
driver: syslog
options:
syslog-facility: "daemon"
tag: "redis"
syslog-address: "tcp://localhost:5514"
api:
image: pt-rails
env_file: .env.dev
networks:
- phototankswarm
command: >
sh -c '
rails s -p 3000 -b 0.0.0.0;
'
volumes:
- /Users/martinhinge/Pictures/docker/phototank:/media/phototank
- ./backend:/usr/src/app
ports:
- "3000:3000"
depends_on:
- db
- redis
- syslog
logging:
driver: syslog
options:
syslog-facility: "daemon"
tag: "rails"
syslog-address: "tcp://localhost:5514"
syslog:
image: syslog
ports:
- "localhost:5514:514"
networks:
- phototankswarm
volumes:
- /tmp:/var/log/syslog
networks:
phototankswarm:
As suggested by @Robert in the comments the solution is to run bundle commands as part of the CMD in the docker-compose file:
The api
service in my compose file thus becomes:
api:
image: pt-rails
env_file: .env.dev
networks:
- phototankswarm
command: >
sh -c '
bundle exec sidekiq -d -L /dev/stdout && bundle exec rails s -p 3000 -b 0.0.0.0
'
volumes:
- /Users/martinhinge/Pictures/docker/phototank:/media/phototank
- ./backend:/usr/src/app
ports:
- "3000:3000"
depends_on:
- db
- redis
- syslog
logging:
driver: syslog
options:
syslog-facility: "daemon"
tag: "rails"
syslog-address: "tcp://localhost:5514"