I’m new at using Docker containers and I’m trying to setup a sandbox environment with an ansible controller and ansible client. For now, I’m going to have both containers share the same image (RHEL8) from the dockerfile below. I’m trying to ‘ssh’ in either direction, but I get "port 22 connection refused. I uncommented out the Port 22 setting in sshd_config, but not sure how to restart sshd service or unblock the firewall port within a container.
Error:
sh-4.4# ssh -v [email protected]
OpenSSH_8.0p1, OpenSSL 1.1.1k FIPS 25 Mar 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config.d/05-redhat.conf
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug1: configuration requests final Match pass
debug1: re-parsing configuration
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config.d/05-redhat.conf
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug1: Connecting to 172.17.0.2 [172.17.0.2] port 22.
debug1: connect to address 172.17.0.2 port 22: Connection refused
ssh: connect to host 172.17.0.2 port 22: Connection refused
Dockerfile:
FROM redhat/ubi8
RUN yum install -y sudo
RUN sudo yum update -y
RUN sudo yum install -y python3
RUN sudo alternatives --set python /usr/bin/python3
RUN sudo yum install -y openssh-server
RUN sudo yum install -y openssh-clients
RUN useradd ansible
RUN usermod --password ansible test123
RUN sudo yum install -y rust
RUN sudo pip3 install --upgrade pip
RUN pip3 install ansible
RUN mkdir /etc/ansible
RUN mkdir /etc/ansible/hosts
EXPOSE 22
ENTRYPOINT ["tail", "-f", "/dev/null"]
2
Answers
I figured out the issue. The fix was to add the following to the dockerfile:
Then I was able to ssh from container to container
It seems you do not build and start the container.
Try to build the image:
and run the container with the 22 port exposed:
Then, you can try to connect with ssh to the created container with
ssh -v ansible@<ip>