Got permission denied while trying to connect to the Docker daemon socket

When we first started using the v2 & telegraf input plugins, there was no problem, but restarting the system suddenly the getting this error ([inputs.docker] Error in plugin: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get “http://%2Fvar%2Frun%2Fdocker.sock/v1.21/containers/json?filters=%7B%22status%22%3A%5B%22running%22%5D%7D&limit=0”: dial unix /var/run/docker.sock: connect: permission denied) and now the InfluxDB 2.0 OSS Metrics & Docker data dashboards are not working… In the database we can see the respective tables are created but they are all empty.

How can we solve this error? Do the system need internet connection for these to work?

Hi @Aritra666B,
Can you trying running:

sudo usermod -aG docker telegraf

Then restart the telegraf service?

Hi @Jay_Clifford ,

I tried it but didn’t work. In the given command I only replaced telegraf with my user.

still get this.
[inputs.docker] Error in plugin: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get “http://%2Fvar%2Frun%2Fdocker.sock/v1.21/containers/json?filters=%7B%22status%22%3A%5B%22running%22%5D%7D&limit=0”: dial unix /var/run/docker.sock: connect: permission denied

Hi @Aritra666B,
Telegraf generates its own user. You need to add Telegraf to the docker group. Please run the above command again as intended :slight_smile:.

Hi @Jay_Clifford ,

If I run that command it gives me error → usermod: user ‘telegraf’ does not exist.

Do I have to create any group at first with name ‘telegraf’ ?

Hi,

How did you install Telegraf? Deb? RPM? is this running in a docker container?

Could you also run ls -l /var/run/docker.sock and provide the output please!

Thanks!

I installed telegraf directly from docker site. : sudo docker pull telegraf. Normaly telegraf is working fine, I mena it’s inserting data to influxdb uisng opcua but the internal docker & influxdb tables are all empty.

After running your command got the following msg:
ubuntu@ubuntu:~$ ls -l /var/run/docker.sock
srw-rwxrw- 1 root docker 0 Jan 10 07:36 /var/run/docker.sock

Hi @Aritra666B,
Ah, my apologies I should have asked if you were using docker. Can you send along your docker-compose?

Did you mount the socket to the container? Here is the raw docker run command:

 docker run -d --name=telegraf \
      --net=influxdb \
      -v /var/run/docker.sock:/var/run/docker.sock \
      -v $PWD/telegraf.conf:/etc/telegraf/telegraf.conf:ro \
      telegraf

Hi @Jay_Clifford ,

Thanks for the help, now we can get data in the internal tables as well.