Saturday, April 28, 2018

Cleaning up Docker containers with xargs

The Linux/UNIX tools landscape is always worth investigating, while you're trying to find a solution for a problem. Because, if you're lucky you don't have to write a script or anything similar: you can just chain existing tools together to build up your custom solution.

Thanks to Dump Tiger and Bjørn, I got to know the xargs command.

One thing that I don't like so much, when I'm starting/stopping Docker containers quite often, is that they'll polute your disc space (depending on the image size).

docker ps -a | grep 'Exited (' | cut -d ' ' -f1 | xargs docker rm

The pipe shown above does the following:
  1. List all Docker containers
  2. Filter the list, so that only those lines that contain the string 'Exited (' will be returned
  3. From all returned lines, cut of the first row (the container ID) by splitting each line on all whitespaces
  4. Now that we've a list of container IDs, we can pipe each container ID into docker rm by using xargs

Friday, April 6, 2018

Debian: OpenVPN Client Config

Getting your OpenVPN client up and running on Debian is easy.

Prerequisites: The openvpn.conf file from your VPN provider.

  1. apt-get instal openvpn
  2. apt-get install resolvconf
  3. Make sure the following settings are enabled in your openvpn.conf:
    • script-security 2
    • up /etc/openvpn/update-resolv-conf
    • down /etc/openvpn/update-resolv-conf
  4. openvpn --config /path/to/openvpn.conf