在 Docker 图像上安装 SSH

Installing SSH on a Docker image

我正在尝试使用以下命令在 docker 映像上安装 SSH:

RUN APT INSTALL -Y SSH

这似乎在映像上安装了 SSH,但是如果我隧道进入 运行ning 容器并手动 运行 命令,我会收到设置区域和时区的提示。是否可以将这些选项传递给安装 SSH 命令? 我能够手动安装 SSH 的容器可以使用以下命令启动:

docker container run -it --rm -p 22:22 ubuntu:latest

我的Docker图片如下:

FROM ubuntu:latest
RUN apt update
apt -y install ssh

谢谢

您可以使用 DEBIAN_FRONTEND 禁用与用户 (DEBIAN_FRONTEND) 的交互:

   noninteractive
          This is the anti-frontend. It never interacts with you  at  all,
          and  makes  the  default  answers  be used for all questions. It
          might mail error messages to root, but that's it;  otherwise  it
          is  completely  silent  and  unobtrusive, a perfect frontend for
          automatic installs. If you are using this front-end, and require
          non-default  answers  to questions, you will need to preseed the
          debconf database; see the section below  on  Unattended  Package
          Installation for more details.

像这样:

FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/London
RUN apt update && \
    apt -y install ...