How to make docker in VS Code devcontainer use the host network

If you have a complex set up, e.g. with VPN and proxy, and docker with an isolated (bridge) network is unable to connect to the internet or is even mis-configuring your DNS name resolution on the host machine (I will add another post on that), the docker option --network=host often helps. It tells docker to simply re-use the network connections of the host machine.

However, this is not the default and there is no central docker configuration file setting that would make this the default behavior, so when you have downloaded a project that ships it’s own VS code devcontainer, chances are that the docker image build will fail (if some RUN commands in the Dockerfile require internet access) or that network access within the running docker devcontainer will not work.

You can add this configuration setting to .devcontainer/devcontainer.json to forward the --network=host option to docker build:

{
  "build": {
    # ...
    "options": [
      "--network=host"
    ]
}

And you can add this configuration setting to .devcontainer/devcontainer.json to forward the --network=host option to docker run:

{
  # ...
  "runArgs": ["--network=host"]
}

Try it out, and you will see the option appear in the docker build / docker run call in the devcontainer start-up log.

How to tar files matching a given name pattern in all subdirectories

This is just a quick repost of https://stackoverflow.com/questions/18731603/how-to-tar-certain-file-types-in-all-subdirectories, because I find it so useful:

Given a directory with deeply nested subdirectories, and I want to just extract e.g. all *.yaml configuration files, this is the command to do it:

find . -name "*.yaml" | tar -cvf my_archive -T -

Linux: Show files from an apt package

As I search for these commands time and time again, I’ll just copy the Post which lists them all:

https://serverfault.com/questions/96964/list-of-files-installed-from-apt-package

To find which files were installed by a package, use dpkg -L:

$ dpkg -L $package

apt-file can tell you which files will be installed by a package before installing it:

root# apt-get install apt-file
root# apt-file update
$ apt-file list $package

NOTE: apt-file needs to be installed first (sudo apt-get install apt-file).

Or if you have the package as a .deb file locally already, you can run dpkg on it:

$ dpkg --contents $package.deb

To find which package provides a file that is already on your system, use:

$ dpkg -S /path/to/file

To find which package provides a file that is not currently on your system, use apt-file again:

$ apt-file search /path/to/file

Random Bash wisdom

I’ve recently found myself writing some bash scripts and I wanted to collect some random wisdom I aggregated:

1. This is a great cheat-sheet for bash if conditions: https://clburlison.com/bash-if-then-cheat-sheet/

2. If you have a back-up solution in case a certain command is not available in the PATH, you can use the following to test it:

if ! command -v my_tool > /dev/null; then
    # do something in case my_tool is not available
fi

NOTE: In bash, you can also use “hash” command, as this post summarizes: https://scripter.co/check-if-a-command-exists-from-shell-script/

3. To get the path of your own script:

SCRIPT_DIR=$(realpath $(dirname "$0"))

4. Understanding Curly braces: https://www.linux.com/topic/desktop/all-about-curly-braces-bash/
Now, I don’t think every variable should be put in ${}, but it’s useful to have a reference on what you can do when using ${} instead of just the $ sign.

5. I like using pushd and popd, but I also like them to be silent. https://serverfault.com/questions/108154/can-i-call-pushd-popd-and-prevent-it-printing-the-stack shows how to do it:

pushd mydir > /dev/null
# work in mydir
popd > /dev/null

Finally, the Wikibook on Bash Shell Scripting is realy good (https://en.wikibooks.org/wiki/Bash_Shell_Scripting).

Linux: Fix missing xorg.conf

I’m using Ubuntu Linux 18.10 with an old Thinkpad T410 laptop and am quite satisfied, but I had to do some work to get the laptop display’s brightness control keys working with my Nvidia graphics card. I had to add the following to xorg.conf:

Option "RegistryDwords" "EnableBrightnessControl=1"

(Source: https://www.thomas-krenn.com/de/wiki/Fehlerhafte_Helligkeitssteuerung_unter_Linux_beim_Thinkpad_T410_beheben )

However, there was no xorg.conf anywhere! I found out after some research that in Ubuntu 18.04 onwards, xorg.conf is not created by default. Run

nvidia-xconfig

and it creates an /etc/X11/xorg.conf. The changes I added there were applied on the next reboot and I was able to use the Fn – Pos1 / End keys for the laptop screen’s brightness control again.