title: docker : how to share ssh-keys between containers?
body: <p>I've 4 containers configured like the following (<code>docker-compose.yml</code>):</p>
  <pre><code>version: '3'
  networks:
    my-ntwk:
      ipam:
        config:
          - subnet: 172.20.0.0/24
  services:
    f-app:
      image: f-app
      tty: true
      container_name: f-app
      hostname: f-app.info.my
      ports:
        - &quot;22:22&quot;
      networks:
        my-ntwk:
          ipv4_address: 172.20.0.5
      extra_hosts:
        - &quot;f-db.info.my:172.20.0.6&quot;
        - &quot;p-app.info.my:172.20.0.7&quot;
        - &quot;p-db.info.my:172.20.0.8&quot;
      depends_on:
        - f-db
        - p-app
        - p-db
    f-db:
      image: f-db
      tty: true
      container_name: f-db
      hostname: f-db.info.my
      networks:
        my-ntwk:
          ipv4_address: 172.20.0.6
    p-app:
      image: p-app
      tty: true
      container_name: p-app
      hostname: p-app.info.my
      networks:
        my-ntwk:
          ipv4_address: 172.20.0.7
    p-db:
      image: p-db
      tty: true
      container_name: prod-db
      hostname: p-db.info.my
      networks:
        my-ntwk:
          ipv4_address: 172.20.0.8
  </code></pre>
  <p>Each image is build by the same <code>Dockerfile</code> :</p>
  <pre><code>FROM openjdk:8
  
  RUN apt-get update &amp;&amp; \
      apt-get install -y openssh-server
  
  EXPOSE 22
  
  RUN useradd -s /bin/bash -p $(openssl passwd -1 myuser) -d /home/nf2/ -m myuser
  
  ENTRYPOINT service ssh start &amp;&amp; bash
  </code></pre>
  <p>Now I want to be able to connect from <code>f-app</code> to any other machine without typing the password when running this line : <code>ssh myuser@f-db.info.my</code>.</p>
  <p>I know that I need to exchange ssh-keys between the servers (thats not a problem). My problem is how to do it with docker containers and when (build or runtime)!</p>