Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

server hostname on which container is running in logs #450

Open
mariaczi opened this issue Jan 16, 2020 · 2 comments
Open

server hostname on which container is running in logs #450

mariaczi opened this issue Jan 16, 2020 · 2 comments

Comments

@mariaczi
Copy link

How we can grab the hostname of the server on which the container is runnig and send this hostname to the logs agregator: syslog-ng, logstash etc.?

Something we got when we use:
docker service logs SERVICE|TASK
And the output is:

node_app_1.7.zyp3bh58k6dn@SRVNAME     | app listening on port 80
node_app_1.7.zyp3bh58k6dn@SRVNAME     | queryDb took 35 ms ("select * from visits limit 1")
node_app_1.7.zyp3bh58k6dn@SRVNAME     | db error Error: read ECONNRESET
node_app_1.7.zyp3bh58k6dn@SRVNAME     |     at TCP.onStreamRead (internal/stream_base_commons.js:201:27) {
node_app_1.7.zyp3bh58k6dn@SRVNAME     |   errno: 'ECONNRESET',
node_app_1.7.zyp3bh58k6dn@SRVNAME     |   code: 'ECONNRESET',
node_app_1.7.zyp3bh58k6dn@SRVNAME     |   syscall: 'read',
node_app_1.7.zyp3bh58k6dn@SRVNAME     |   fatal: true
node_app_1.7.zyp3bh58k6dn@SRVNAME     | }
node_app_1.7.zyp3bh58k6dn@SRVNAME     | /usr/src/app/src/db-mysql.js:139
node_app_1.7.zyp3bh58k6dn@SRVNAME     |         throw err;
node_app_1.7.zyp3bh58k6dn@SRVNAME     |         ^
node_app_1.7.zyp3bh58k6dn@SRVNAME     | 
node_app_1.7.zyp3bh58k6dn@SRVNAME     | Error: read ECONNRESET
node_app_1.7.zyp3bh58k6dn@SRVNAME     |     at TCP.onStreamRead (internal/stream_base_commons.js:201:27) {
node_app_1.7.zyp3bh58k6dn@SRVNAME     |   errno: 'ECONNRESET',
node_app_1.7.zyp3bh58k6dn@SRVNAME     |   code: 'ECONNRESET',
node_app_1.7.zyp3bh58k6dn@SRVNAME     |   syscall: 'read',
node_app_1.7.zyp3bh58k6dn@SRVNAME     |   fatal: true
node_app_1.7.zyp3bh58k6dn@SRVNAME     | }
@mariaczi
Copy link
Author

OK. I'm able to have hostname on which the containter is running using environment variable for example:

-e "SYSLOG_HOSTNAME={{.Container.Config.Hostname}}@`hostname`"

@edorgeville
Copy link
Contributor

You can also mount the host /etc/hostname inside the container as described in the README: https://github.com/gliderlabs/logspout#using-logspout-in-a-swarm

version: "3"
networks:
  logging:
services:
  logspout:
    image: gliderlabs/logspout:latest
    networks:
      - logging
    volumes:
      - /etc/hostname:/etc/host_hostname:ro
      - /var/run/docker.sock:/var/run/docker.sock

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants