FROM ubuntu:24.04 ENV DEBIAN_FRONTEND=noninteractive \ TZ=Europe/Paris # 先安裝建立使用者需要的套件 RUN apt-get update && apt-get install -y --no-install-recommends \ adduser \ sudo \ && rm -rf /var/lib/apt/lists/* # 建立 user RUN adduser --disabled-password --gecos '' --shell /bin/bash user \ && echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user ENV HOME=/home/user WORKDIR /home/user/app RUN mkdir -p /home/user/app /home/user/.cache /home/user/.config \ && chown -R user:user /home/user \ && chmod -R 777 /home/user # 複製安裝腳本並執行 (root) COPY setup.sh /home/user/app/setup.sh RUN chmod +x /home/user/app/setup.sh && /home/user/app/setup.sh # 切換到 user USER user # 複製啟動腳本 COPY --chown=user --chmod=755 start.sh /home/user/app/start.sh # 複製應用程式 COPY --chown=user --chmod=755 . /home/user/app ENV PYTHONUNBUFFERED=1 \ GRADIO_ALLOW_FLAGGING=never \ GRADIO_NUM_PORTS=1 \ GRADIO_SERVER_NAME=0.0.0.0 \ GRADIO_THEME=huggingface \ SYSTEM=spaces \ SHELL=/bin/bash RUN ls -al /home/user/app CMD ["/home/user/app/start.sh"]