esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

Docker requires root #3558

Open Janoz-NL opened 2 years ago

Janoz-NL commented 2 years ago

The problem

Docker image requires root. When running the container using --user the compilation of the images give persmission denied errors. Had to change ownership of /.platformio and /piolibs within the container to fix this.

Which version of ESPHome has the issue?

2022.8.1

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP8266

Board

No response

Component causing the issue

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

INFO Reading configuration /config/appie.yaml...
INFO Generating C++ source...
INFO Compiling app...
Error: Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/platformio/__main__.py", line 102, in main
    cli()  # pylint: disable=no-value-for-parameter
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/dist-packages/platformio/cli.py", line 71, in invoke
    return super().invoke(ctx)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1654, in invoke
    super().invoke(ctx)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/platformio/__main__.py", line 56, in cli
    maintenance.on_platformio_start(ctx, force, caller)
  File "/usr/local/lib/python3.9/dist-packages/platformio/maintenance.py", line 39, in on_platformio_start
    telemetry.on_command()
  File "/usr/local/lib/python3.9/dist-packages/platformio/telemetry.py", line 288, in on_command
    resend_backuped_reports()
  File "/usr/local/lib/python3.9/dist-packages/platformio/telemetry.py", line 440, in resend_backuped_reports
    tm = app.get_state_item("telemetry", {})
  File "/usr/local/lib/python3.9/dist-packages/platformio/app.py", line 178, in get_state_item
    with State() as state:
  File "/usr/local/lib/python3.9/dist-packages/platformio/app.py", line 80, in __init__
    os.makedirs(core_dir)
  File "/usr/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/.platformio'

Additional information

No response

tomaszduda23 commented 1 year ago
mkdir /.platformio
chown -R 1000:1000 /.platformio/
chown -R 1000:1000 /piolibs/
kjkent commented 1 year ago

Also encountered this issue as I don't want to run HA or esphome in privileged mode. To expand on the already-provided solution:

1) In docker host:

# Get the name of your docker container
docker ps

# Enter the container using a root bash shell (esphome is the name of my container)
docker exec -u root -it esphome /bin/bash

2) Now, as root within the container, run the commands as provided by @tomaszduda23:

mkdir /.platformio
chown -R 1000:1000 /.platformio/
chown -R 1000:1000 /piolibs/

3) Rerun the build you attempted, which should now work.

walle86 commented 1 year ago

This worked for me: I added these Environment variables to the esphome service:

environment:
      PLATFORMIO_CORE_DIR: .plattformio
      PLATFORMIO_GLOBALLIB_DIR: .plattformioLibs

Both dir names are in reverence to your /config dir. So you don't have to change directory ownership in the container and it will also work after you rebuild the container.

d3jong commented 1 year ago

This worked for me: I added these Environment variables to the esphome service:

environment:
      PLATFORMIO_CORE_DIR: .plattformio
      PLATFORMIO_GLOBALLIB_DIR: .plattformioLibs

Both dir names are in reverence to your /config dir. So you don't have to change directory ownership in the container and it will also work after you rebuild the container.

I've had the same issue with 'v2023.5.1' and this fixed it for me. Why is this necessary?

jgus commented 1 year ago

Same issue in 2023.8.0; adding the platformio env vars did the trick for me too. :+1:

Ulrar commented 11 months ago

Agreed, these should probably point to the cache directory by default, or at least the config

Cyberbeni commented 7 months ago

I'm also getting the following warning during build (in addition to the errors mentioned above):

WARNING: The directory '/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.

Adding PIP_CACHE_DIR: "/config/.pip" to the environment seems to fix the issue.

ptr727 commented 3 months ago

FYI: https://github.com/ptr727/ESPHome-NonRoot