Build Docker image to install/run openssh-server

  dockerfile, nexus, ssh, yum

I have a Dockerfile that was successfully built on Azure DevOps to run an application deployed on App Service. But I wanted to SSH into the application and it doesn’t allow me to and generated an error message "SSH CONNECTION CLOSED – Error: connect ECONNREFUSED". Upon researching, I think that I need to install openssh-server in my Dockerfile. Based on what I found, the sonatype/nexus3 image is based on Red Hat Universal Base Image, not alpine or ubuntu hence my understanding is that I need to use yum install instead of apt-get or apk commands.

RUN yum install -y openssh-server.

However, when I execute the command above in my Dockerfile, it generated an error below.

Step 11/31 : RUN yum install -y openssh-server
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Red Hat Universal Base Image 8 (RPMs) - BaseOS   13 kB/s | 3.8 kB     00:00
Red Hat Universal Base Image 8 (RPMs) - BaseOS  2.2 MB/s | 787 kB     00:00
Red Hat Universal Base Image 8 (RPMs) - AppStre  30 kB/s | 4.2 kB     00:00
Red Hat Universal Base Image 8 (RPMs) - AppStre 4.4 MB/s | 2.4 MB     00:00
Red Hat Universal Base Image 8 (RPMs) - CodeRea 109 kB/s | 3.8 kB     00:00
No match for argument: openssh-server
Error: Unable to find a match: openssh-server
The command '/bin/sh -c yum install openssh-server' returned a non-zero code: 1
##[error]The command '/bin/sh -c yum install openssh-server' returned a non-zero code: 1
##[error]The process '/usr/bin/docker' failed with exit code 1

Here’s the Dockerfile that I use. Also, I’m not sure if the last command to start the SSH service is correct or not.

FROM sonatype/nexus3:3.33.0
USER root
COPY nexus-2020.lic /opt/sonatype/sonatype-work/nexus-2020.lic
RUN cp /tmp/logback-access.xml /opt/sonatype/nexus/etc/logback/logback-access.xml
ADD sshd_config /etc/ssh/
RUN yum install openssh-server
ENV JAVA_HOME=/opt/java
ENV SONATYPE_DIR=/opt/sonatype
EXPOSE 8081 2222
USER nexus
CMD ["sh", "-c", "${SONATYPE_DIR}/start-nexus-repository-manager.sh"]
CMD ["sshd_config", "-D"]

Any help would be much appreciated. Thank you.

Source: Dockerfile Questions

LEAVE A COMMENT