I’m completely new to linux and docker concepts
In my windows machine I boot up centos7 in virtual box
while running docker-compose build I get
/bin/sh: /usr/sbin/sshd-keygen: No such file or directory
How to rectify it
I tried to create a remote user
docker-compose.yml
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- "$PWD/jenkins_home:/var/jenkins_home"
networks:
- net
remote_host:
container_name: remote-host
image: remote-host
build:
context: centos7
networks:
- net
networks:
net:
DockerFile
FROM centos
RUN yum -y install openssh-server
RUN useradd remote_user &&
echo "Thevenus987$" | passwd remote_user --stdin &&
mkdir /home/remote_user/.ssh &&
chmod 700 /home/remote_user/.ssh
COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
RUN chown remote_user:remote_user -R /home/remote_user/.ssh &&
chmod 600 /home/remote_user/.ssh/authorized_keys
RUN /usr/sbin/sshd-keygen
CMD /usr/sbin/sshd -D
10
Answers
1)
in Dockerfile change:
to
2) or try
if that is included and exists anywhere in your $PATH, it will execute.
FROM centos pulls the latest by default which does not include sshd-keygen.
You need to change your Dockerfile to:
Change the base image
FROM centos
toFROM centos:7
and it will workJust change FROM centos
FROM centos:7
That error happened because before docker centos run centos7 and now run centos 8
The Dockerfile should be like this:
The problem is with this line in your Dockerfile:
RUN /usr/sbin/sshd-keygen
This is what you get when this line gets executed: /etc/rc.d/init.d/functions: No such file or directory.
/usr/sbin/sshd-keygen: command not found.
This init.d/functions file is different for different linux distros. It’s specific to whatever distribution you’re running. This file contains functions to be used by most or all shell scripts stored in the /etc/init. d directory.
To try this yourself simply pull the CentOS:7 image from docker hub and test your RUN steps from your Dockerfile as follows:
docker container run -i -t -d --name test centos:7
docker exec -it test bash
cd /etc/rc.d/init.d
ls -a
There is no file called functions in this directory.
In CentOS:7 Docker image you have to simply install the package initscripts in order for this script to be installed, so add these lines to your Dockerfile:
FROM centos:7
RUN yum install -y initscripts
In Dockerfile
Change
RUN /usr/sbin/sshd-keygen
// Centos8 doesn’t accept this commandto
RUN ssh-keygen -A
// This works.I hope this solution works fine.
try below command instead of
RUN /usr/sbin/sshd-keygen
and also as others pointed out use:
FROM centos:7
RUN ssh-keygen -A
just use FROM centos:7 (instead of using centos8 base image)
and
yum install -y initscripts
Note: Updated initscripts bug fix enhancement package fixes several bugs and add one enhancement are now available for Red Hat Enterprise Linux 6/7.
you don’t need to remove or twek this below line at all
RUN /usr/sbin/sshd-keygen
it will work 100% ..
To learn more about initscripts bug fix enhancement:
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/6.5_technical_notes/initscripts