Working with Docker filters in python

I needed to man-in-the-middle traffic of Docker containers to automatically extract game server status information from plaintext http requests to their master server.
So I wrote a python script for that, but I had some weird behavior on the Docker network “name” filter.
The behavior seems not to be documented on the documentation.

Setup

Game servers are running inside an overlay network called “condor2”.
On the Docker host, I run a python script to extract game server information from network traffic flowing through the Docker overlay network.

Versions

# docker version
 Client: Docker Engine - Community
  Version:           19.03.2
  OS/Arch:           linux/amd64
 Server: Docker Engine - Community
  Engine:
   Version:          19.03.2
   API version:      1.40 (minimum version 1.12)
  containerd:
   Version:          1.2.6
# pip3 freeze | grep docker
 docker==3.7.3
# python3 --version
 Python 3.5.3

Problem

Running this piece of script

import docker
d = docker.from_env()
n = d.networks.list(filters={"name":"condor2"})

returns an object like that one:

>>> print (n)
[<Network: 228e98c554>, <Network: b9aafep0a6>]

Both networks have “condor2” in their name:

# docker network inspect 228e98c554 | grep Name    
"Name": "condor2",
# docker network inspect b9aafep0a6 | grep Name
        "Name": "prod_dvaec_condor2-bots_default",

Solution

To get exact matches for your filter, you need to use regex inside the filter:

#!/usr/bin/env python3
import docker
d = docker.from_env()
n = d.networks.list(filters={"name":"^condor2$"})

The result looks like that now:

>>> print (n)
[<Network: 228e98c554>]

Bingo. That’s what I actually needed.

Simple podcast downloader

This simple python3 script will fetch all RSS attachments and save them in the format “Podcast Title” – “Episode Name”.mp3

Installing the dependencies:

pip3 install feedparser
import feedparser
import subprocess

feedURL = ''

d = feedparser.parse(feedURL)

for entry in d['entries']:
    episodeName = d['feed']['title'] + " - " + entry['title']
    for link in entry['links']:
        if link['type'] != 'text/html':
            url = link['href']
            subprocess.run(["wget", "-c", "-O", episodeName + ".mp3", url])

Filter mailing lists with Dovecot Sieve

require ["fileinto", "variables"];

if header :matches "List-Post" "*<mailto:**@*.*.*>" {
  fileinto "INBOX.lists.${5}.${3}"; stop;
}

if header :matches "List-Post" "*<mailto:**@*.*>" {
  fileinto "INBOX.lists.${4}.${3}"; stop;
}

if header :matches "X-Mailing-List" "*@*.*.*" {
  fileinto "INBOX.lists.${3}.${1}"; stop;
}

if header :matches "X-Mailing-List" "*@*.*" {
  fileinto "INBOX.lists.${2}.${1}"; stop;
}

Teamspeak Dockerfile > Healthcheck

FROM teamspeak

RUN apk --update --no-cache add netcat-openbsd

HEALTHCHECK --interval=15s --timeout=1s --start-period=5s --retries=3 CMD echo quit | nc 127.0.0.1 10011 || false
# docker ps --filter ancestor=teamspeak

CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                 PORTS                                                                        NAMES
748e7f873a07        teamspeak_teamspeak   "entrypoint.sh ts3se…"   5 hours ago         Up 5 hours (healthy)   0.0.0.0:10011->10011/tcp, 0.0.0.0:9987->9987/udp, 0.0.0.0:30033->30033/tcp   dvaec_teamspeak