title: how to map ports when deploying docker on AWS EB
body: <p>I have a service I want to deploy onto an environment in elastic beanstalk. If I want to build it locally I would use this line:</p>
  
  <pre><code>docker run --detach --name my-nlx-inway (some env en volume parameters) --publish 4443:8443 nlxio/inway:latest
  </code></pre>
  
  <p>I have tried setting all of this in a Dockerfile:</p>
  
  <pre><code>FROM nlxio/inway:latest
  ENV NAME my-nlx-inway
  EXPOSE 4443
  </code></pre>
  
  <p>When I deploy everything goes smoothly, my service is registered only it appears offline. I think it is in the mapping.
  With the command I say <code>--publish 4443:8443</code> and in the Dockerfile I only say <code>EXPOSE 4443</code>.</p>
  
  <p>So I tried building a <code>dockerrun.aws.json</code></p>
  
  <pre><code>{
    "AWSEBDockerrunVersion": "1", 
    "Ports": [
      {
        "ContainerPort": 8443,
        "HostPort":4443
      }
    ]
  }
  </code></pre>
  
  <p>I added the mapping with a configfile:</p>
  
  <pre><code>container_commands:
    00001_add_mapping:
      command: 'sed -i "s/docker run -d/docker run -p 4443:8443 -d/" /opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh'
  </code></pre>
  
  <p>And I see the result in the logging:</p>
  
  <pre><code>'docker ps' ran at Tue Jun 11 12:20:02 UTC 2019: 
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                NAMES
  741a52caf467        f06676e20291        "/usr/local/bin/nlx-â€¦"   11 minutes ago      Up 11 minutes       4443/tcp, 0.0.0.0:4443-&gt;8443/tcp   optimistic_johnson
  </code></pre>