SocatHelper¶
-
class
dna.
SocatHelper
(dna)[source]¶ The
socat
helper class that binds container ports to unix socketsThe motivation behind using
socat
is that simply having docker publish ports and having nginx proxy to them would result in host ports having to be defined and occupied. The better solution is to have an additional lightweight container that can bridge to each service and bind its port to a socket. This socket is created in a folder that is located on the host but mounted to thesocat
container, so that the host’s nginx webserver may proxy to it.- Parameters
dna (
DNA
) – the DNA instance
The
socat
container for a DNA instanceinst
is calledinst-socat
. The bridge network for a DNA instanceinst
is calledinst
.-
SOCAT_CMD
= 'socat unix-listen:/socks/{service}.sock,fork,reuseaddr tcp-connect:{service}:{port}'¶ The command to bind
port
in theservice
container to a socket namedservice.sock
-
DOCKERFILE
= 'FROM alpine:edge\nARG VERSION=1.7.3.4-r1\nRUN apk --no-cache add socat=${VERSION}\n'¶ The Dockerfile for
socat`
-
bind
(service, port)[source]¶ Bind
port
inside theservice
container to a socket calledservice.sock
- Parameters
service (str) – the name of the service
port (str) – the port to be bound