Login from Docker
I have a rails app running through docker. I am bringing up an application using docker-compose (below). The whole application includes mysql, redis, rails (including 3rd party workers), nginx (with frontend support) and an rsyslog server that translates all logs to Loggly
My problem is solved for the logging part. Logs from all services are mostly sent except from my logs from sidekiq. When I start sidekiq with bundler exec sidekiq
, the logs are output to the console (stdout), but I can't see them when I find the tail of / var / log / messages on the rsyslog server.
I followed this tutorial while setting up registration in docker:
https://medium.com/@yoanis_gil/logging-with-docker-part-1-b23ef1443aac
My thinking is that whatever goes to stdout in the docker container should be written to the docker log engine, and with my setup this means it should go to the syslog server ...
Docker 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:
source to share
As suggested by @Robert in the comments, the solution is to run the package commands as part of the CMD in the docker compose file:
So the service api
in my comp file is:
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"
source to share