I want to be able to execute a command from a jenkins server inside a build container. I imagine this would have to be done using ssh. Here is my attempt sofar:
Dockerfile for the build server:
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install git -y
RUN apt-get install wget -y
RUN apt-get install socat -y
RUN apt-get install unzip -y
RUN apt-get install chrpath -y
RUN apt-get install build-essential -y
RUN apt-get install texinfo -y
RUN apt-get install xterm -y
RUN apt-get install python3 -y
RUN apt-get install python -y
RUN apt-get install locales -y
RUN apt-get install cpio -y
RUN apt-get install diffstat -y
RUN apt-get install gawk -y
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' |chpasswd
RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN mkdir /root/.ssh
EXPOSE 22
RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment
RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
RUN echo "LANG=en_US.UTF-8" > /etc/locale.conf
RUN locale-gen en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
RUN useradd -ms /bin/bash builder
USER builder
WORKDIR /home/builder/
CMD ["/usr/sbin/sshd", "-D"]
docker-compose file:
version: '3'
services:
yocto-server:
build: .
container_name: yocto-server
tty: true
ports:
- 22:22
networks:
- build-network
jenkins-master:
image: jenkins/jenkins
container_name: jenkins-master
privileged: true
working_dir: /home/jenkins
depends_on:
- yocto-server
ports:
- 8080:8080
networks:
- build-network
links:
- yocto-server
networks:
build-network:
driver: bridge
Now I try to run a bash inside of the jenkins container and ssh into the yocto container:
sudo docker-compose run jenkins-master /bin/bash
Starting yocto-server ... done
jenkins@b79689ec8403:/home/jenkins$ ping yocto-server
PING yocto-server (172.18.0.2) 56(84) bytes of data.
64 bytes from yocto-server.yoctodocker_build-network (172.18.0.2): icmp_seq=1 ttl=64 time=0.076 ms
64 bytes from yocto-server.yoctodocker_build-network (172.18.0.2): icmp_seq=2 ttl=64 time=0.044 ms
^C
--- yocto-server ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1026ms
rtt min/avg/max/mdev = 0.044/0.060/0.076/0.016 ms
jenkins@b79689ec8403:/home/jenkins$ ssh root@yocto-server
ssh: connect to host yocto-server port 22: Connection refused
I suspect something is wrong with the port exposure. The error reads as if the ports not open at all, despite it being exposed in the docker file and mapped in the compose file.