You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker运行Home Assistant镜像遇/init权限拒绝的解决方案咨询

解决Docker运行Home Assistant镜像时"/init: permission denied"错误

问题场景

构建Home Assistant镜像命令:

docker build --build-arg BUILD_FROM=homeassistant/amd64-homeassistant-base:latest . -t homeassistant:local

推送至Docker Hub后运行镜像命令:

sudo docker run -d --name homeassistant --privileged --restart=unless-stopped -v /home/smhmlab/Dashboard/HomeAssistant:/config --network=host keshavr/ha-repo:custom-0.31.88

运行后报错:

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/init": permission denied: unknown.

使用的Dockerfile内容:

ARG BUILD_FROM
FROM ${BUILD_FROM}

# Synchronize with homeassistant/core.py:async_stop
ENV \
S6_SERVICES_GRACETIME=220000

ARG QEMU_CPU

WORKDIR /usr/src

## Setup Home Assistant Core dependencies
COPY requirements.txt homeassistant/
COPY homeassistant/package_constraints.txt homeassistant/homeassistant/
RUN \
pip3 install \
    --no-cache-dir \
    --no-index \
    --only-binary=:all: \
    --find-links "${WHEELS_LINKS}" \
    -r homeassistant/requirements.txt

COPY requirements_all.txt home_assistant_frontend-* home_assistant_intents-* \
homeassistant/
RUN \
if ls homeassistant/home_assistant_frontend*.whl 1> /dev/null 2>&1; then \
    pip3 install \
        --no-cache-dir \
        --no-index \
        homeassistant/home_assistant_frontend-*.whl; \
fi \
&& if ls homeassistant/home_assistant_intents*.whl 1> /dev/null 2>&1; then \
    pip3 install \
        --no-cache-dir \
        --no-index \
        homeassistant/home_assistant_intents-*.whl; \
fi \
&& \
    LD_PRELOAD="/usr/local/lib/libjemalloc.so.2" \
    MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" \
    pip3 install \
        --no-cache-dir \
        --no-index \
        --only-binary=:all: \
        --find-links "${WHEELS_LINKS}" \
        -r homeassistant/requirements_all.txt

## Setup Home Assistant Core
COPY . homeassistant/
RUN \
pip3 install \
    --no-cache-dir \
    --no-index \
    --only-binary=:all: \
    --find-links "${WHEELS_LINKS}" \
    -e ./homeassistant \
&& python3 -m compileall \
    homeassistant/homeassistant

# Home Assistant S6-Overlay
COPY rootfs /

WORKDIR /config

解决方法

1. 修复本地rootfs目录中init文件的权限

错误核心是镜像内/init文件缺少执行权限,大概率是本地rootfs目录下的init文件本身没有执行位,COPY到镜像后权限丢失:

  • 本地检查权限:
    ls -l rootfs/init
    
  • 若权限不是-rwxr-xr-x,添加执行权限:
    chmod +x rootfs/init
    
  • 重新构建并推送镜像:
    docker build --build-arg BUILD_FROM=homeassistant/amd64-homeassistant-base:latest . -t homeassistant:local
    docker tag homeassistant:local keshavr/ha-repo:custom-0.31.88
    docker push keshavr/ha-repo:custom-0.31.88
    

2. 在Dockerfile中强制设置/init权限

如果本地权限正常但COPY后权限丢失,可在Dockerfile中显式添加权限设置:
在COPY rootfs /之后追加:

RUN chmod +x /init

修改后的对应片段:

# Home Assistant S6-Overlay
COPY rootfs /
RUN chmod +x /init

WORKDIR /config

完成后重新构建镜像。

3. 验证基础镜像的S6-Overlay完整性

确认homeassistant/amd64-homeassistant-base:latest基础镜像本身包含合法的S6-Overlay环境:

docker run -it --rm homeassistant/amd64-homeassistant-base:latest ls -l /init

若基础镜像内/init权限异常,更换为与Home Assistant Core版本匹配的官方指定基础镜像。

4. 解决跨平台文件系统权限丢失问题

如果在Windows/macOS环境构建,可能因文件系统不支持Linux权限位导致COPY后权限丢失,可使用Docker 20.10+支持的--chmod参数:
修改COPY命令为:

COPY --chmod=755 rootfs /

内容的提问来源于stack exchange,提问作者Kapil Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 01:46:35