docker - 在 Docker 镜像上安装 SSH

标签 docker ubuntu ssh dockerfile apt

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

RUN APT INSTALL -Y SSH

这似乎在图像上安装了 SSH,但是如果我隧道进入正在运行的容器并手动运行命令,我会收到设置区域和时区的提示。是否可以将这些选项传递给安装 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 ...

关于docker - 在 Docker 镜像上安装 SSH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62653871/

相关文章:

linux - 无法连接到 vscode 服务器,scp : No such file or directory

Docker compose,是否可以在已安装的卷中安装文件夹?

docker - 连接期间出错 : Get http://%2Fvar%2Frun%2Fdocker. sock/v1.40/containers/json : read unix @->/var/run/docker. sock:读取:连接被对等方重置

macos - docker-compose 重启后保留以前的环境变量

linux - Bash 脚本 tee 命令语法问题

ssh - 我理解RSA加密: How are the files in ~/. ssh的数学与理论相关吗?

Docker 撰写错误 : Service 'web' failed to build : COPY failed: forbidden path

apache - 在 ubuntu 上安装 Xampp apache 时出错

ubuntu - pyspark 找不到有效的 SPARK_HOME

hadoop - 使用 SSH 从本地访问我的虚拟机时遇到问题