ubuntu/debian apt安装时有交互式选择界面如何规避(容器化)
问题
容器构建中tzdata 在安装时的交互式时区选择界面。
Configuring tzdata ------------------ Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities, representing the time zones in which they are located. 1. Africa 4. Arctic 7. Australia 10. Pacific 2. America 5. Asia 8. Europe 11. Etc 3. Antarctica 6. Atlantic 9. Indian 12. Legacy apt 默认自动选择
解决
目标是 apt 安装时自动选择(无交互)。
1.直接用非交互模式安装
1 | export DEBIAN_FRONTEND=noninteractive |
或者一行写法:
1 | DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata |
这样 apt 会自动使用默认配置,不弹出菜单。适合 Docker、CI、批量部署。
2.提前设定时区再静默安装
例如设为上海时区:
1 | ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime |
安装过程中就不会再询问。
3.如果系统已经安装过 tzdata又想静默重配
1 | DEBIAN_FRONTEND=noninteractive dpkg-reconfigure tzdata |
4.自动化构建环境
1 | ENV DEBIAN_FRONTEND=noninteractive |