title: Deploying Docker to AWS Elastic Beanstalk -- how to forward port to host? (port binding)
body: <p>I have a project set up with CircleCI that I am using to <a href="https://circleci.com/docs/docker" rel="nofollow">auto-deploy to Elastic Beanstalk</a>. My EBS environment is a single container, auto-scaling, web environment. I am trying to run a service that listens on raw socket port 8080.</p>
  
  <p>My Dockerfile: </p>
  
  <pre><code>FROM golang:1.4.2
  
  ...
  
  EXPOSE 8080
  </code></pre>
  
  <p>My Dockerrun.aws.json.template:</p>
  
  <pre><code>{
    "AWSEBDockerrunVersion": "1",
    "Authentication": {
      "Bucket": "&lt;bucket&gt;",
      "Key": "&lt;key&gt;"
    },
    "Image": {
      "Name": "project/hello:&lt;TAG&gt;",
      "Update": "true"
    },
    "Ports": [
      {
        "ContainerPort": "8080"
      }
    ]
  }
  </code></pre>
  
  <p>I have made sure to expose port 8080 on the "role" assigned to my project environment.</p>
  
  <p>I used the exact deployment script from the CircleCI tutorial linked above (except with changed names).</p>
  
  <p>Within the EC2 instance that is running my EBS application, I can see that the Docker container has run successfully, except that Docker did not forward the exposed port to the host container. I have encountered this in the past when I ran <code>docker run ....</code> without the <code>-P</code> flag.</p>
  
  <p>Here is an example session after SSH-ing into the machine:</p>
  
  <pre><code>[ec2-user@ip-xxx-xx-xx-xx ~]$ sudo docker ps
  CONTAINER ID        IMAGE                              COMMAND                CREATED             STATUS              PORTS               NAMES
  a036bb061aea        aws_beanstalk/staging-app:latest   "/bin/sh -c 'go run    3 days ago          Up 3 days           8080/tcp            boring_hoover
  [ec2-user@ip-xxx-xx-xx-xx ~]$ curl localhost:8080
  curl: (7) Failed to connect to localhost port 8080: Connection refused
  </code></pre>
  
  <p>What I expect to see is the <code>-&gt;8080</code> or whatever in the container that forwards it onto the host.</p>
  
  <p>When I do <code>docker inspect</code> on my container, I also see that these two configurations are not what I want:</p>
  
  <pre><code>    "PortBindings": {},
      "PublishAllPorts": false,
  </code></pre>
  
  <p>How can I trigger a port binding in my application?</p>
  
  <p>Thanks in advance.</p>