Docker serivce remote_host failed to build: The command '/bin/sh -c sudo'

Viewed 9

Got stuck with docker configuration for a remote user. When running a build command getting an error chmod: cannot access '/home/remote_user/.ssh'....'Service remote_host failed to build: The command /bin/sh -c chown remote_user:remote_user'

Further when i go to /home directory I don't see the folder created either but the step to create the folder passed successfully

The structure of the folder looks like this for main Dockerfile:

/home/useradmin/jenkins

the Dockerfile for remote_user is

/home/useradmin/jenkins/centos7

this is the main Docker file

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  # image that we're going to build 
    build:
      context: centos7  # where the Dockerfile is located
    networks:
      - net            # same network to allow communication between jenkins service and remote_host
networks:
    net:

remote_host Dockerfile

FROM centos

RUN yum -y install openssh-server

# Add this to fix error: passwd command not found
RUN yum -y install passwd

RUN useradd remote_user && \
  echo "1234" | passwd remote_user --stdin && \
  mkdir /home/remote_user/.ssh && \
  chmod 700 /home/remote_user/.ssh

# Modified Dockerfile for Section 4:27
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 -- this has error when building, instead, use below
RUN sshd-keygen

# instruct which command the container should run/start
CMD /usr/sbin/sshd -D
0 Answers
Related