10

supervisor.sock refused connection in docker container

I have tried to fix it by supervisorctl unix:///var/run/supervisor.sock refused connection AND Overlayfs does not work with unix domain sockets

However, it still does not work in my debain server.


Here is my docker_supervisor.conf

FROM python:2.7

RUN pip install supervisor

RUN mkdir /app
WORKDIR /app

COPY docker_supervisor.conf /app

RUN supervisord -c docker_supervisor.conf

CMD ["supervisorctl", "-c", "docker_supervisor.conf", "restart", "apiapp:"]

Here is docker_supervisor.conf

[unix_http_server]
file=/var/run/docker_supervisor.sock
chown=root:root
chmod=0777

[supervisord]
logfile=/var/run/docker_supervisor.log
pidfile=/var/run/docker_supervisor.pid

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = 
supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/docker_supervisor.sock

[group:apiapp]
programs=api_web

[program:api_web]
user=root
directory=/app
command=python echo "OKOKOK"

sudo docker build --no-cache -t test .
Successfully built c3b4061fc9f7


sudo docker run -v $(pwd):/app test
unix:///var/run/docker_supervisor.sock refused connection

I have tried execute

sudo docker run --tmpfs /var/run -v $(pwd):/app test

But it gets the same result "unix:///var/run/docker_supervisor.sock refused connection"

How to fix it and let supervisor run in container?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Jolly23
  • 879
  • 1
  • 8
  • 13

2 Answers2

2

It's also worth checking that supervisor is actually running

supervisord

Running this will try and start supervisor, or throws an error if it is already running. For me, it's always a stale connection which breaks supervisor

Luke Madhanga
  • 6,871
  • 2
  • 43
  • 47
  • 1
    Thanks @Luke Madhanga :) I ran supervisord command and it says the socket has been staled and it also automatically relinks and updates the socket file which has solves my problem. – kta Apr 09 '23 at 05:01
1

I just ran into the same issue and solved it by changing the socket file path to /dev/shm/supervisor.sock.

The supervisord.conf file now looks like this:

[unix_http_server]
file=/dev/shm/supervisor.sock                 ; <-- change it here
chmod=0700

[supervisord]
nodaemon=true                                 ; <-- add nodaemon for Docker
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisor

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///dev/shm/supervisor.sock     ; <-- and change it here too

[program:app]
...

Note: It is recommended to use supervisorctl with the -c argument to make sure that it is reading the correct config file. Otherwise, it might fall back to one of the default ones and try to connect using the default socket file /var/run/supervisor.sock which doesn't work.

Edit - added more things to watch for

Note 2: Make sure Supervisor server is running before using client.

# Start server
supervisord -c /path/to/supervisor.conf
# Then use client
supervisorctl -c /path/to/supervisor.conf status

Note 3: Make sure the socket file exists. If it doesn't, you can create it, for example, like this (reference):

python -c "import socket as s; sock = s.socket(s.AF_UNIX); sock.bind('/dev/shm/supervisor.sock')"

Note 4: Keep in mind that it is also possible to use TCP instead of Unix socket file.

[inet_http_server]
port = 127.0.0.1:9001

[supervisorctl]
serverurl = http://127.0.0.1:9001

; Rest of the supervisor.conf file...

References:

Glen
  • 87
  • 9