SocatHelper

class dna.SocatHelper(dna)[source]

The socat helper class that binds container ports to unix sockets

The 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 the socat container, so that the host’s nginx webserver may proxy to it.

Parameters

dna (DNA) – the DNA instance

The socat container for a DNA instance inst is called inst-socat. The bridge network for a DNA instance inst is called inst.

SOCAT_CMD = 'socat unix-listen:/socks/{service}.sock,fork,reuseaddr tcp-connect:{service}:{port}'

The command to bind port in the service container to a socket named service.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 the service container to a socket called service.sock

Parameters
  • service (str) – the name of the service

  • port (str) – the port to be bound

unbind(service, port)[source]

Unbind port inside the service container from service.sock

The port is required here to determine which socat process to terminate on the socat container for this DNA instance.

Parameters
  • service (str) – the name of the service

  • port (str) – the port to be unbound

bind_all(services)[source]

Bind all the services to their respective ports

Parameters

services (list[Service]) – the services to bind