Mahoney / docker-etc-hosts

Adds entries to /etc/hosts to allow addressing docker containers by name

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make the script work on an M1 mac

Mahoney opened this issue · comments

The script currently requires bash 5 & needs to run as root (it alters /etc/hosts).

A Mac comes with bash 3.2 (and zsh 5.x).

brew install bash on an M1/ARM64 Mac installs bash 5.x, but to /opt/homebrew/bin - which is not on root's path. (On an x64 Mac it is installed to /usr/local/bin, which is on root's path, so it works.)

So #! /usr/bin/env bash loads bash 3.2.

Options:

  1. Alter root's path to include /opt/homebrew/bin
  2. Find some mechanism for a script to discover later versions of bash if installed?!
  3. Migrate the script to zsh which is installed
  4. Migrate the script to bash 3.2
  5. Just document that it's the user's problem to make /usr/bin/env bash resolve to bash 5.x
  6. Use another approach entirely (dns server running in docker?)

I'm not a massive fan of any of them...

  1. Making root's path include homebrew when homebrew doesn't seems like an invasive thing to do... I'd like this to be less reliant on running as & mucking about with root, not more
  2. I don't even know if this is possible
  3. I've got a reasonable way with this... need a replacement for shopt -s extglob and possibly then replacements for bash's ${sanitised//+([^A-Za-z0-9\.])/-}, ${sanitised#[^[:alnum:]]} & ${sanitised%[^[:alnum:]]} variable substituting
    More seriously, the tests are in bats which seems to be bash specific - I haven't located a zsh test framework yet.
  4. Not sure how to work around the lack of associative arrays...
  5. I hate when things don't install nicely - it's already a bit painful with all the manual chown. Also I'd want to give specific instructions on the "right" way to do this and I'm not sure what that is - alter root's path to include /opt/homebrew/bin I suppose, bit see objections to 1!
  6. This exists - e.g. https://github.com/aacebedo/dnsdock or https://github.com/mageddo/dns-proxy-server - run a dns server inside docker that will pick up containers starting and stopping and use it as the host's DNS.
    I was reluctant to go this way because mucking about with how macOs does DNS choice is something I'm a bit uncomfortable with. If docker isn't running your DNS is broken, for a start. And you have to work out how to configure this DNS server to resolve to the correct "real" DNS server(s). Just mutating /etc/hosts leaves the actual DNS server configuration alone.