bash apt-get install tzdata 非交互式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44331836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
apt-get install tzdata noninteractive
提问by PYA
When I try to
当我尝试
apt-get install -y tzdata
the command line option for picking timezone shows up. I am trying to use this in a script to do some setup, how can I make the apt-get run without user input?
选择时区的命令行选项出现了。我正在尝试在脚本中使用它进行一些设置,如何在没有用户输入的情况下运行 apt-get?
I know to reconfigure the tzdata I can do
我知道要重新配置我可以做的 tzdata
echo "America/New_York" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
But when installing I need it to run fully even if it doesn't set the right timezone, I can always reconfigure it.
但是在安装时我需要它完全运行,即使它没有设置正确的时区,我总是可以重新配置它。
I tried
我试过
echo 5 | apt-get install -y tzdata
but it is not working as expected.
但它没有按预期工作。
回答by PYA
This is the script I used
这是我使用的脚本
(Updated Version with input from @elquimista from the comments)
(使用@elquimista 来自评论的输入更新版本)
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime
apt-get install -y tzdata
dpkg-reconfigure --frontend noninteractive tzdata
Seems to work fine.
似乎工作正常。
回答by Youngjae
If someone wants to achieve it in Dockerfile
, use as below.
如果有人想在 中实现它Dockerfile
,请使用如下。
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -y install tzdata
回答by Jean Paul Ruiz
All credit for this should go to @PYA but the right order should be:
对此的所有功劳都应该归功于@PYA,但正确的顺序应该是:
ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime
export DEBIAN_FRONTEND=noninteractive
apt-get install -y tzdata
dpkg-reconfigure --frontend noninteractive tzdata