3

I currently have supervisor serving my Django Application which I then expose on port 8002 in my Docker file. This all works ok...

[program:app]
command=gunicorn app.core.wsgi:application -c /var/projects/app/server/gunicorn.conf
user=webapp

backlog     = 2048
chdir       = "/var/projects/apps"
bind        = "0.0.0.0:8002"
pidfile     = "/var/run/webapp/gunicorn.pid"
daemon      = False
debug       = False

In Docker

# Expose listen ports
EXPOSE 8002

However, I have been told it is better to use a socket over a port but, I'm unsure how to "EXPOSE" a socket in my Docker file. This is how far I have got:

New supervisor config....

backlog     = 2048
chdir       = "/var/projects/apps"
bind        = "unix:/var/run/webapp/gunicorn.sock"
pidfile     = "/var/run/webapp/gunicorn.pid"
daemon      = False
debug       = False

Docker

# Expose listen ports
EXPOSE ???? (may be unix:/var/run/webapp/gunicorn.sock fail_timeout=0;???)

How do I expose the socket?

scytale
  • 12,346
  • 3
  • 32
  • 46
MarkK
  • 968
  • 2
  • 14
  • 30
  • possible duplicate of [Can docker port forward to a unix file socket on the host container?](http://stackoverflow.com/questions/24956322/can-docker-port-forward-to-a-unix-file-socket-on-the-host-container) – satoru Aug 24 '15 at 11:08
  • @satoru thats using the RUN command. – MarkK Aug 24 '15 at 13:36

1 Answers1

5

EXPOSE only works with UDP and TCP sockets.

If you want to make a Unix domain socket available outside of your container, you will need to mount a host directory inside the container and then place the socket there. For example, if you were to:

docker run -v /srv/webapp:/var/run/webapp ...

Then /var/run/webapp/gunicorn.sock in your container would be /srv/webapp/gunicorn.sock on your host.

Of course, this assumes that you have something running on your host, or in another container that also has access to /srv/webapp, that is able to consume that socket and use it to provide a service.

larsks
  • 277,717
  • 41
  • 399
  • 399