Running daphne in Docker without supervisor

Currently, I’m running daphne using supervisor. This is my supervisor config:

[supervisord]
user = root
nodaemon = true

[fcgi-program:daphne]
socket=tcp://api:9000
directory=/home/docker/api
ommand=./.docker/services/api/files/startup-operations.sh && daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --proxy-headers main.asgi:application
numprocs=2
process_name=asgi%(process_num)d
autostart=true
autorestart=false
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
redirect_stderr=true
killasgroup=true
startsecs=0
exitcodes=0

Here, the channels docs give exactly one example, and it’s using supervisor: https://channels.readthedocs.io/en/latest/deploying.html

However, I have read this: https://advancedweb.hu/supervisor-with-docker-lessons-learned/

…which advocates for not using supervisor in docker, and I would agree with the article.

One problem with using supervisor that the article doesn’t discuss is that I have an in-memory database that I need to be available for the main application.

The above config file is just one program that runs a startup-operations.sh script, but before, it used to be two programs: One program loaded the data into memory, and the other program ran the main application.

Of course, I could load that data into memory in startup-operations.sh and be done with it, but that doesn’t remove supervisor from my image. It seems that if I’m just running one series of commands, I should be able to not use supervisor in my image.

I also had errors resulting from running out of space in my limited EC2 instance that both builds and runs this image (I know, it would be ideal to build the image locally and upload it to ECR, then run it on the server, but it’s a testing server and we don’t have that kind of capacity right now), and I wanted to reduce the storage space required to both build the image and run the container. Removing supervisor from the build and container would help with that.

Considering the linked article, the problem with sharing memory between supervisor programs, and the storage space limitations, I decided to try remove supervisor from both the build process and the final image of my dockerized application.

I used to have this CMD directive in my Dockerfile:

CMD ["supervisord", "--nodaemon", "-c", "/etc/supervisor/conf.d/supervisor.conf"]

I now have this CMD directive in my Dockerfile:

CMD ["/bin/bash", "-c", "mkdir -p /run/daphne && /home/docker/api/.docker/services/api/files/startup-operations.sh && daphne -u /run/daphne/daphne.sock --fd 0 --proxy-headers main.asgi:application"]

This builds and runs fine, but when I try to access an endpoint (such as https://host/admin/), I get a 502 Bad Gateway error from nginx, and this error shows in the logs for the main application container:

daphne.server CRITICAL Listen failure: [Errno 88] Socket operation on non-socket

The server shuts down as a result.

I figure it has to do with this line in the original supervisor config:

socket=tcp://api:9000

Is there a line I can add to me CMD directive to create this socket and avoid this error?

By the way, this is the contents of startup-operations.sh:

#!/usr/bin/env bash

echo Waiting for the database to be ready...
./wait-for-db.sh

echo Collecting static files...
python manage.py collectstatic --no-input
echo Done.

echo Running migrations...
python manage.py migrate
echo Done.

echo Creating admin user...
python manage.py create_admin_user
echo Done.

# NOTE: This is the in-memory database.
#  We are using local memory to store vectors in development/testing
#  and a separate server in staging/production.
echo Initializing vector store...
python manage.py initialize_vector_store
echo Done.

echo Startup operations completed successfully!

exit 0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật