Connecting to a host service from within a container using Docker for Mac

TL;DR Use host.docker.internal. When you are running Docker on Linux and want to access services on the host from within a container, you can make use of the docker0 bridge interface (ip a s docker0). This does not work when running Docker for Mac as the interface is inside a separate virtual machine (which you can confirm by getting a shell in that vm: screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty) and thus not visible on the local host. ...

October 11, 2020

UnicodeError when running Python script via macOS LaunchAgent

If you are getting UnicodeErrors when reading/manipulating files using a Python script launched by a LaunchAgent or crontab, the problem might lie in the “current locale encoding”. Sample script Let’s assume you have the following code in a script set up to be launched by a LaunchAgent (also see my article on LaunchAgents): with open(some_path_to_file) as f: f.read() Let’s also assume that some_path_to_file points to a txt file containing some emojis (hey, why not? 😎) or some other unicode characters. ...

December 7, 2018

Using launchd agents to schedule scripts on macOS

Even though launchd has been around for quite some time now, I was still using crontab for scheduling some of my scripts until recently. Since launchd LaunchAgents can do much more and don’t expect your computer to be running at all times, it’s time to start using them more 😎. Let’s see how we can easily set up a LaunchAgent to run a Python script for the current user in regular intervals: ...

March 13, 2018

VPN: Temporarily solve same subnet conflicts

I recently had the problem of needing to establish a connection to a server behind a VPN that was in the same subnet as the network I was connecting from. Every call I wanted to make to the server on the remote network wouldn’t go through as it was looking for the server on the local network. To eventually reach the server, I temporarily added a route to the routing tables, telling the client it should transmit traffic to the destination ip through the interface of the VPN connection. ...

September 27, 2017

Running Flask on macOS with mod_wsgi/wsgi-express

Flask is a (micro) web development Framework for Python. It is fairly simple to get started. All you need to do is to pip install Flask into your virtualenv, give the FLASK_APP environment variable your file and run flask run (described in detail in installation and quick start). This will launch the development server and you can instantly start hacking around. When you want to use your Apache webserver, however, you need to install and configure a WSGI module. When I first wanted to do this I tried to install mod_wsgi via brew (brew install mod_wsgi from the homebrew/apache tap), but quickly ran into some (apparently common) issues with the XCode toolchain. Then I discovered that there is a much easier way of installing mod_wsgi as a Python package. ...

August 5, 2017