0

I am using docker-API module for accessing service list and the replica information. It works better in swarm-mode and on manager node. But if the app goes on worker node, it gives me the following error "unexpected - This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again". following is my code,

const Docker = require('node-docker-api').Docker
const docker = new Docker({ socketPath: '/var/run/docker.sock' })
const services = await docker.service.list()

Is it possible to get the service list on both node by giving any options or permissions to worker node? Also Is it possible to get by running app using docker-compose or kubernetes?

aryan
  • 163
  • 1
  • 1
  • 11

1 Answers1

1

As docker docs state:

Worker nodes don’t participate in the Raft distributed state, make scheduling decisions, or serve the swarm mode HTTP API.

Possible solutions:

  • You may consider running only manager nodes in your swarm topology.

  • Alternatively, you can use placement constraint --constraint node.role==manager for you node.js based docker service

This way your service containers would run only on manager nodes which serve the swarm mode HTTP API.

rok
  • 9,403
  • 17
  • 70
  • 126