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

群晖RS1221+ NAS中Docker镜像无法安装locales及locales-all求助

解决Docker构建Ubuntu镜像时locales包找不到的问题

问题原因

  • 群晖环境下,Ubuntu 20.04镜像默认的apt源可能无法正常访问,导致包索引更新不完整,找不到locales和locales-all包。
  • Dockerfile中存在路径笔误:/us/share/zoneinfo应为/usr/share/zoneinfo。
  • 多次单独执行RUN命令会导致镜像层冗余,且可能因为缓存的apt update结果过期引发问题。

修正后的Dockerfile

FROM ubuntu:20.04

# 替换为国内Ubuntu源(解决群晖环境下源访问问题)
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" > /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list

# 更新源并安装所需包,合并命令减少镜像层
RUN apt update && \
    apt install -y locales locales-all tzdata openssh-server sudo bash-completion tree git && \
    locale-gen en_US.UTF-8 && \
    update-locale LANG=en_US.UTF-8 && \
    rm -rf /var/lib/apt/lists/*  # 清理apt缓存,减小镜像体积

# 设置时区(修正路径笔误)
ENV TZ=Europe/Zurich
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 创建用户并配置SSH
RUN useradd -m -d /home/app -s /bin/bash -G sudo app && \
    echo 'app:pass1234' | chpasswd

EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]

关键修改点说明

  • 替换apt源:使用国内阿里云源,确保群晖环境下能正常获取包索引,解决locales包找不到的问题。
  • 合并RUN命令:将多个apt相关命令合并,避免缓存过期导致的问题,同时减少镜像层数。
  • 清理apt缓存:添加rm -rf /var/lib/apt/lists/*,减小最终镜像的体积。
  • 修正时区路径:把/us/share/zoneinfo改为正确的/usr/share/zoneinfo。
  • 移除无效命令:删除RUN service ssh start,因为Docker容器启动时会执行CMD命令启动sshd,构建时启动服务无意义。

构建命令

执行以下命令重新构建镜像:

sudo docker build -t appy:1 .

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 01:20:30