title: How to make a TCP outgoing connection with Docker container?
body: <p>My Go application makes <a href="https://github.com/andradei/quickfix/blob/feature/ssl/connection.go#L75" rel="nofollow noreferrer">TLS connections via <code>tls.Dial()</code></a> to exchange data.</p>
  
  <p>It works fine when run from the host:</p>
  
  <p><a href="https://i.stack.imgur.com/Srmvg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Srmvg.jpg" alt="enter image description here"></a></p>
  
  <p>But the outgoing connection doesn't seem to work when the app is run from a Docker container. The app hangs indefinitely.</p>
  
  <p><a href="https://i.stack.imgur.com/dIIKM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dIIKM.png" alt="enter image description here"></a></p>
  
  <p><strong>Note 1</strong>: Same behavior with using <code>docker run -p $(docker-machine ip):2500:2500 ...</code></p>
  
  <p><strong>Note 2</strong>: VM doesn't have extra port forwarding settings other than the default settings that came with docker-machine's default VM.</p>
  
  <p>Docker image build with Dockerfile:</p>
  
  <pre><code>FROM golang:latest
  
  RUN mkdir -p "$GOPATH/src/path/to/app"
  # Install dependencies
  RUN go get github.com/path/to/dep
  
  VOLUME "$GOPATH/src/path/to/app"
  EXPOSE 2500
  WORKDIR "$GOPATH/src/path/to/app"
  CMD ["go", "run", "main.go"]
  </code></pre>
  
  <p>Host is OS X running <em>docker-machine</em>.</p>
  
  <h2>Question</h2>
  
  <p>How can I make the TCP outgoing connection to work?</p>