S
S
sha2562019-12-31 18:58:18
SSH
sha256, 2019-12-31 18:58:18

How to connect to Docker from one container to another via SSH?

Friends, hello everyone!
There are two containers in the docker, both under CentOS7, one acts as an Ansible server.
What is the point: I can’t hook up to the second container from under Ansible, I get an error:

Failed to connect to the host via ssh: OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket \"/root/.ansible/cp/ansible-ssh-127.0.0.1-42222-root\" does not exist\r\ndebug2: ssh_connect: needpriv 0\r\ndebug1: Connecting to 127.0.0.1 [127.0.0.1] port 42222.\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug1: connect to address 127.0.0.1 port 42222: Connection refused\r\nssh: connect to host 127.0.0.1 port 42222: Connection refused\r\n

At the same time, via SSH from the host to the container, I cling without a hitch ..
Inventory content:
[staging_servers]
bsk_devserv  ansible_connection=ssh ansible_host=127.0.0.1 ansible_port=42222  ansible_user=root ansible_password=welcome1 ansible_ssh_private_key_file=/ssh_host_dsa_key

Ansible.cfg content
[defaults]
host_key_checking 	= false
inventory			= ./inventory

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Syomov, 2019-12-31
@sha256

The problem is probably that in that container you need to specify not 127.0.0.1 port 42222 to connect, but the ip of the container, or its name, and the desired port.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question