Raspberry Pi Docker Container to send all LAN DNS requests to Cloudflare’s 1.1.1.1 DNS over TLS

I wanted to implement this on a Raspberry Pi that I have running Docker.  However, I wasn’t able to find an image in Docker Hub for the ARM architecture that the Raspberry Pi uses so I made my own based on the x86-64 image, here.

  • Place the Dockerfile and unbound.conf in the same directory.
  • Docker file:
FROM arm32v6/alpine:3.7
EXPOSE 53/udp
RUN apk add --update --no-cache -q --progress unbound && \
    rm -rf /etc/unbound/unbound.conf /var/cache/apk/*
COPY unbound.conf /etc/unbound/unbound.conf
ENTRYPOINT unbound -d
  • unbound.conf:
server:
  verbosity: 0
  use-syslog: no
  qname-minimisation: yes
  do-tcp: yes
  prefetch: yes
  rrset-roundrobin: yes
  use-caps-for-id: yes
  do-ip4: yes
  do-ip6: no
  interface: 0.0.0.0
  access-control: 0.0.0.0/0 allow
forward-zone:
  name: "."
  forward-addr: 1.1.1.1@853
  forward-addr: 1.0.0.1@853
  forward-ssl-upstream: yes

 

  • Build the Docker image:
docker build -t itinnovations/cloudflaretlsdns:latest .

 

  • Start a container as a daemon from the above image:
docker run -d \
  --name=CloudflareTLSDNS \
  --restart=unless-stopped \
  -p 53:53/udp \
  itinnovations/cloudflaretlsdns

 

  • Configure all clients to point to the IP address of the Docker Host for DNS.

EDUP 802.11n Mini Wi-Fi Adapter Sleeping

 

I bought some EDUP 802.11 N Mini Wi-Fi Adapters from China.  They’re cheap and do a fine job plugged into my Raspberry Pi’s.

However, by default, they always go to sleep which makes it difficult to connect to them via ssh etc.  To fix this, here’s what I did:

To identify the USB WLAN Adapter I did the following:

$ lsusb

Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Then:

$ lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 5: Dev 4, If 0, Class=Vendor Specific Class, Driver=rtl8192cu, 480M

From that I was able to derive that the WLAN adapter was using the rtl8192cu drivers.

A bit of Googling later, I was able to disable power management on the Wifi adapter, like this:

sudo nano /etc/modprobe.d/8192cu.conf

Add the following lines:

# Disable power management options
8192cu rtw_power_mgnt=0 rtw_enusbss=0

Reboot…

Run:

cat /sys/module/8192cu/parameters/rtw_power_mgnt

It should return 0 if the power management is off.

Bask in the glory of your WiFi adapter that stays up all the time 🙂

Deploy Watchtower in Docker

Watchtower is an application that will monitor your running Docker containers and watch for changes to the images that those containers were originally started from. If watchtower detects that an image has changed, it will automatically restart the container using the new image.

  • A 16 megabyte limit is set on the container, in this instance.
  • I’ve added a hostname for this container because Watchtower sends emails with the hostname of the Watchtower Docker container in the subject line.  By setting my own hostname instead of the default Docker generated hostname, I can glance at the email and see which of my hosts containers have just been updated.
  • Email notifications are configured using the container environment variables using the -e flags.  These can be omitted if you don’t want any notifications.
docker run -d \
  --name watchtower \
  --hostname=azure.dockerhost001 \
  --restart=unless-stopped \
  --memory=16mb \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e WATCHTOWER_NOTIFICATIONS=email \
  -e [email protected] \
  -e [email protected] \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER=your.smtp.server \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER=your.smtp.username \
  -e WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD=your.smtp.password \
  v2tec/watchtower \
  --cleanup

Deploy Portainer in Docker

Portainer is an Open-Source lightweight Management UI which allows you to easily manage your Docker Hosts or Swarm Clusters

  • Port 9000 of the container is published to the host
  • A 16 megabyte limit is set on the container, in this instance.
  • Data is persisted in a named volume called ‘portainer_data’
docker run -d \
  --name portainer \
  --restart=unless-stopped \
  --memory=16m \
  -p 9000:9000 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v portainer_data:/data \
  portainer/portainer

The container can also be deployed using the more explicit –mount flag which became available for standalone containers in Docker 17.06.

docker run -d \
  --name portainer \
  --restart=always \
  --memory=16m \
  -p 9000:9000 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  --mount source=portainer_data,destination=/data \
  portainer/portainer

Install Docker and Compose on Ubuntu 16.04 LTS

#!/bin/bash

apt-get update

apt-get install \
 apt-transport-https \
 ca-certificates \
 curl \
 software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

add-apt-repository \
 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
 $(lsb_release -cs) \
 stable"

apt-get update

apt-get install -y \
  docker-ce \
  docker-compose

If you plan on using the –memory flag when creating containers, you may need to enable memory and swap accounting in the Kernel.

  1. Log into the Ubuntu host as a user with sudo privileges.
  2. Edit the /etc/default/grub file. Add or edit the GRUB_CMDLINE_LINUX line to add the following two key-value pairs:
    GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
  3. Save and close the file.
  4. Update GRUB.
    $ sudo update-grub

    If your GRUB configuration file has incorrect syntax, an error occurs. In this case, repeat steps 3 and 4.

    The changes take effect when the system is rebooted.

More detailed information can be found in the Docker Post-Installation Steps for Linux.

Sonic Pi Coding Class 004

It was agreed to give a small prize to the student who worked the hardest during the class and who also worked the hardest in producing their final piece/s of music based on a brief.  I’ve created links here to the more obscure parts of the prize so that the recipient has a starting point to work out what they can be used for!

Arduino code for the Ultrasonic Ruler that was worked on in class can be found in my GitHub repository, here.

Install pip on OS X via Terminal


GUTE-URLS

Wordpress is loading infos from ahmadawais

Please wait for API server guteurls.de to collect data from
ahmadawais.com/install-pip-ma...

sudo easy_install pip

Get Stock Quote from Yahoo using Node-RED

[
    {
        "id": "d5d3c55c.ff8808",
        "type": "debug",
        "z": "3b163621.c03b8a",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "false",
        "x": 930,
        "y": 180,
        "wires": []
    },
    {
        "id": "39834827.c17818",
        "type": "http request",
        "z": "3b163621.c03b8a",
        "name": "Yahoo Stock",
        "method": "GET",
        "ret": "txt",
        "url": "http://download.finance.yahoo.com/d/quotes.csv?s=^IXIC&f=nsl1opc1p2&e=.csv",
        "tls": "",
        "x": 510,
        "y": 180,
        "wires": [
            [
                "247647e3.b30f88",
                "5db14531.5fb30c"
            ]
        ]
    },
    {
        "id": "5aba260a.74be08",
        "type": "inject",
        "z": "3b163621.c03b8a",
        "name": "Click me to request a stock quote...",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": true,
        "x": 210,
        "y": 180,
        "wires": [
            [
                "39834827.c17818"
            ]
        ]
    },
    {
        "id": "247647e3.b30f88",
        "type": "csv",
        "z": "3b163621.c03b8a",
        "name": "Columns",
        "sep": ",",
        "hdrin": "",
        "hdrout": "",
        "multi": "one",
        "ret": "\\n",
        "temp": "1,2,3,4,5,6,7",
        "x": 720,
        "y": 180,
        "wires": [
            [
                "d5d3c55c.ff8808"
            ]
        ]
    },
    {
        "id": "2f5e310b.99ce8e",
        "type": "comment",
        "z": "3b163621.c03b8a",
        "name": "Readme...",
        "info": "Reference for requesting stock quote...\nhttps://support.klipfolio.com/hc/en-us/articles/215546368-Use-Yahoo-Finance-as-a-data-source-\n\nTo play around, you may be able to change the \nURL in the node that says Yahoo Stock to \nthe URL of your Restful API?\n\nAnyway, aside from that, if you click on the \nlittle square box to the RHS of the node that\nsays \"Click me to request a stock quote...\"\nthat will inject a new timestamp and make a new\nrequest\n\nThere are two outputs.  Check the Debug tab to see them\n\n1 - The raw csv from Yahoo\n2 - The CSV converted to JSON\n\nGood luck!",
        "x": 100,
        "y": 100,
        "wires": []
    },
    {
        "id": "5db14531.5fb30c",
        "type": "debug",
        "z": "3b163621.c03b8a",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "false",
        "x": 730,
        "y": 260,
        "wires": []
    }
]

Install Docker and Compose on Debian 9 Stretch

#!/bin/bash

apt-get update

apt-get install -y \
  apt-transport-https \
  ca-certificates \
  curl \
  gnupg2 \
  software-properties-common

curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -

add-apt-repository \
  "deb [arch=amd64] https://download.docker.com/linux/debian \
  $(lsb_release -cs) \
  stable"

apt-get update

apt-get install -y \
  docker-ce \
  docker-compose

If you plan on using the –memory flag when creating containers, you may need to enable memory and swap accounting in the Kernel.

  1. Log into the Debian host as a user with sudo privileges.
  2. Edit the /etc/default/grub file. Add or edit the GRUB_CMDLINE_LINUX line to add the following two key-value pairs:
    GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
  3. Save and close the file.
  4. Update GRUB.
    $ sudo update-grub

    If your GRUB configuration file has incorrect syntax, an error occurs. In this case, repeat steps 3 and 4.

    The changes take effect when the system is rebooted.

More detailed information can be found in the Docker Post-Installation Steps for Linux.

Sonic Pi Coding Class 003

Last week we wrote a function to set the volume based on musical dynamics like ‘ppp’ or ‘fff’

Functions can also be used to return information to us.

An example of a function that returns a value is below. Type it in and see how it works.

define :get_volume do |music_notation|
  # Write your code here to work out volume level
  # corresponding to music_notation like 'ppp'
  
  # Return the volume level like this
  # return volume_level
  
  # Or we could just return a number for this
  # example to see how it works
  return 0.1234
end

# Now write some code to use the function get_volume
my_volume = get_volume("ppp")
print my_volume

What I would like you to do is to modify last weeks function so that when you pass it a musical notation for volume, like ‘ppp’, it returns a number between 0 and 1.0 for Sonic Pi to use as part of an :amp property.

Once you have that function working, make your own piece of music up that uses this function as many times as you can!

Below is one way of achieving the task. If you are stuck, type this in yourself and then make your own piece of music up that uses this function as many times as you can!

# First, we define the function
#
# Function: get_volume
#
# Input:
#          Gets an amp level for a musical notation passed
#          in as a string.
#          Examples of musical notation: ppp, fff, mf etc
#
# Returns:
#          A number between 0 and max_amp
#
# Reference: https://en.wikipedia.org/wiki/Dynamics_(music)
#
define :get_volume do |music_notation|
  max_velocity = 127.0
  max_amp = 1.0
  velocity_ratio = max_amp / max_velocity
  
  case music_notation
  when "ppp"
    return velocity_ratio * 16
  when "pp"
    return velocity_ratio * 33
  when "p"
    return velocity_ratio * 49
  when "mp"
    return velocity_ratio * 64
  when "mf"
    return velocity_ratio * 80
  when "f"
    return velocity_ratio * 96
  when "ff"
    return velocity_ratio * 112
  when "fff"
    return velocity_ratio * 127
  else
    # Unknown music notation so return max volume
    return velocity_ratio * 127
  end
end

# This is where we start to play our music

# Use the variable my_volume to hold the volume level returned from the function get_volume
my_volume = get_volume("mf")

# Play a note and set the amp (amplifier) level to the value stored in the variable my_volume
play 80, amp: my_volume
sleep 1

# Another way we can do it is like this
play 80, amp: get_volume("fff")
sleep 1