Wednesday, January 5, 2022

[SOLVED] Installing SSH on a Docker image

Issue

I'm trying to install SSH on a docker image using the command:

RUN APT INSTALL -Y SSH

This seemingly installs SSH on the image, however if I tunnel into a running container and run the command manually I get prompted to set both Region and Timezone. Is it possible to pass these options to the install SSH command? The container I am able to manually install SSH on can be started with the command below:

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

My Docker Image is as follows:

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

Thanks


Solution

You can use DEBIAN_FRONTEND to disable interaction with user (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.

Like this:

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


Answered By - Exploding Kitten