title: SSH Agent forwarding inside docker compose container
body: <p><code>Could not open a connection to your authentication agent.</code></p>
  
  <p>I am following the <a href="https://gist.github.com/d11wtq/8699521">approach of mounting the <code>$SSH_AUTH_SOCK</code> as a volume</a>, but doing so with compose.  </p>
  
  <h2>Setup</h2>
  
  <p><code>~/.ssh/config</code></p>
  
  <pre><code>Host *
    ForwardAgent yes
  </code></pre>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM atlashealth/ruby:2.2.2
  
  RUN apt-get update -qq &amp;&amp; \
      apt-get install -qy build-essential libxml2-dev libxslt1-dev \
              g++ qt5-default libqt5webkit5-dev xvfb dbus \
              libmysqlclient-dev \
              mysql-client openssh-client git &amp;&amp; \
  
      # cleanup
      apt-get clean &amp;&amp; \
      cd /var/lib/apt/lists &amp;&amp; rm -fr *Release* *Sources* *Packages* &amp;&amp; \
      truncate -s 0 /var/log/*log
  </code></pre>
  
  <p>Compose yaml:</p>
  
  <pre><code>web:
    build: "."
    environment:
    - SSH_AUTH_SOCK=/ssh-agent
    volumes:
    - "$SSH_AUTH_SOCK:/ssh-agent"
  </code></pre>
  
  <p><strong>NOTE:</strong> I have interpolation running on my compose, so <code>$SSH_AUTH_SOCK</code> is substituted with <code>/private/tmp/com.apple.launchd.ZxGtZy6a9w/Listeners</code> for example.</p>
  
  <p>I have forwarding setup on my host OSX properly, it works against another ubuntu host.</p>
  
  <h2>Run</h2>
  
  <p><code>docker-compose run web bash</code></p>
  
  <h2>In-Container</h2>
  
  <p>When I run <code>ssh-add -L</code>, it states <code>Could not open a connection to your authentication agent.</code></p>
  
  <p>When I run <code>ssh-agent</code>, it yields</p>
  
  <pre><code>SSH_AUTH_SOCK=/tmp/ssh-vqjuo7FIfVOL/agent.21; export SSH_AUTH_SOCK;
  SSH_AGENT_PID=22; export SSH_AGENT_PID;
  echo Agent pid 22;
  </code></pre>
  
  <p>When I run <code>echo $SSH_AUTH_SOCK</code> from bash, it yields <code>/ssh-agent</code></p>
  
  <h2>Question</h2>
  
  <p>It seems that compose is making the <code>SSH_AUTH_SOCK</code> available to <code>bash</code>, but it seems that the <code>ssh-agent</code> is not getting that same <code>env</code>.  What am I missing?</p>