SOLVED: Error setting up local add-on testing environment on Mac

Hi Folks,

I’m following the directions on the Local add-on testing page using a Mac running OS X 11.3.1.

My error log after rebuilding my container and running the “Start Home Assistant” task is below.

I attempted debugging by dropping to the Docker CLI and trying to create the hassio network manually, but that didn’t work.

$ docker network create \
  --driver=bridge \
  --subnet=172.30.32.0/23 \
  --ip-range=172.30.33.0/24 \
  --gateway=172.30.32.0 \
  hassio

Error Log

Start Test-Env
update-alternatives: using /usr/sbin/iptables-legacy to provide /usr/sbin/iptables (iptables) in manual mode
update-alternatives: error: alternative /usr/sbin/iptables-legacy for ip6tables not registered; not setting
Fails adjust ip6tables
Starting docker.
Waiting for docker to initialize...
Docker was initialized
Total reclaimed space: 0B
Cleaning up stopped containers...
Container name cannot be empty
Startup dbus
unix:path=/var/run/dbus/system_bus_socket,guid=72b32998241def6c0394af8f6094deae
Startup udev
Starting version 241
Unable to find image 'homeassistant/amd64-hassio-supervisor:2021.05.dev0301' locally
2021.05.dev0301: Pulling from homeassistant/amd64-hassio-supervisor
540db60ca938: Pull complete 
5410ef35c7ab: Pull complete 
eebec9a33904: Pull complete 
2f698171abbe: Pull complete 
d5ecbe636a25: Pull complete 
564b4c8fcf87: Pull complete 
95371a052e4c: Pull complete 
bc7dadd33921: Pull complete 
d87227e7d06d: Pull complete 
ccabd5035be8: Pull complete 
e35cfd4460f3: Pull complete 
dfb684fd2045: Pull complete 
467af05c8f42: Pull complete 
Digest: sha256:d69270bbdf832ea147af2140fab9b28999710621907d6e1b9e56d95c26dcc713
Status: Downloaded newer image for homeassistant/amd64-hassio-supervisor:2021.05.dev0301
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] udev.sh: executing... 
[06:31:57] INFO: Using udev information from host
[cont-init.d] udev.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[06:31:57] INFO: Starting local supervisor watchdog...
21-05-07 06:31:57 INFO (MainThread) [__main__] Initializing Supervisor setup
21-05-07 06:31:57 INFO (MainThread) [supervisor.docker.network] Can't find Supervisor network, creating a new network
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/docker/api/client.py", line 268, in _raise_for_status
    response.raise_for_status()
  File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localhost/v1.41/networks/create

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/src/supervisor/supervisor/__main__.py", line 41, in <module>
    coresys = loop.run_until_complete(bootstrap.initialize_coresys())
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/usr/src/supervisor/supervisor/bootstrap.py", line 60, in initialize_coresys
    coresys = CoreSys()
  File "/usr/src/supervisor/supervisor/coresys.py", line 68, in __init__
    self._docker: DockerAPI = DockerAPI()
  File "/usr/src/supervisor/supervisor/docker/__init__.py", line 96, in __init__
    self.network: DockerNetwork = DockerNetwork(self.docker)
  File "/usr/src/supervisor/supervisor/docker/network.py", line 25, in __init__
    self.network: docker.models.networks.Network = self._get_network()
  File "/usr/src/supervisor/supervisor/docker/network.py", line 91, in _get_network
    return self.docker.networks.create(
  File "/usr/local/lib/python3.8/site-packages/docker/models/networks.py", line 156, in create
    resp = self.client.api.create_network(name, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/docker/api/network.py", line 153, in create_network
    return self._result(res, json=True)
  File "/usr/local/lib/python3.8/site-packages/docker/api/client.py", line 274, in _result
    self._raise_for_status(response)
  File "/usr/local/lib/python3.8/site-packages/docker/api/client.py", line 270, in _raise_for_status
    raise create_api_error_from_http_exception(e)
  File "/usr/local/lib/python3.8/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
    raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 500 Server Error for http+docker://localhost/v1.41/networks/create: Internal Server Error ("Failed to Setup IP tables: Unable to enable SKIP DNAT rule:  (iptables failed: iptables --wait -t nat -I DOCKER -i hassio -j RETURN: iptables: No chain/target/match by that name.
 (exit status 1))")
21-05-07 06:31:58 ERROR (MainThread) [asyncio] Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f75e496bc70>
21-05-07 06:31:58 ERROR (MainThread) [asyncio] Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f75e496bee0>
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.
Stopping in container docker...
Your host might have been left with unreleased resources

Press any key to close the terminal.

UPDATE: Ok, I’m way out of my wheelhouse, here, but I was able to get things working by:

  • Rebuilding container
  • Running Start Home Assistant task
  • Waiting for above error
  • Opening docker CLI
  • Typing what’s in the codeblock, below
  • Rerunning Start Home Assistant task
# iptables -t nat -N DOCKER
# iptables -t nat -N hassio
# iptables --wait -I FORWARD -o hassio -j DOCKER
iptables v1.8.2 (legacy): Couldn't load target `DOCKER':No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
# iptables -t nat -N DOCKER
iptables: Chain already exists.
# iptables --wait -I FORWARD -o hassio -j DOCKER
iptables v1.8.2 (legacy): Couldn't load target `DOCKER':No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
# service docker restart
[ ok ] Stopping Docker: docker.
[ ok ] Starting Docker: docker.
# iptables --wait -I FORWARD -o hassio -j DOCKER

It’s been years (decades) since I’ve used iptables, and my Docker-fu is rusty, but I hope this thread helps someone.

Huge thanks to the folks on this thread, who pointed me in the right direction.

FINAL UPDATE: Here’s how to actually fix this issue…

Add the following line to your devcontainer.json:

"postCreateCommand": "pre-commit install",

So, if you are following the official documentation, your updated devcontainer.json should be:

// Based on https://github.com/issacg/hassio-addon-devcontainer
{
	"name": "Home Assistant Add-Ons",
	"context": "..",
	"dockerFile": "Dockerfile",
	"appPort": ["7123:8123", "7357:4357"],
	"postCreateCommand": "pre-commit install",
    "postStartCommand": "service docker start",
	"runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"],
	"extensions": [
		"timonwong.shellcheck",
		"esbenp.prettier-vscode"
	],
	"settings": { 
		"terminal.integrated.shell.linux": "/bin/bash"
	}
}