1

I am running a Docker container inside AWS Elastic Beanstalk, running Amazon's 'Amazon Linux', which I believe is a CentOS derivative.

In my development environment, I'd like to enable debugging on my app so I can remote debug from my local machine. This of course requires an additional port, but AWS by default will only map one port in the Docker container onto the host.

I'm on the machine, and I can see that the Docker container has a local address (172.x.x.x), and I can hit the debugging port on that address directly when I'm on the host. The problem is that this address is of course not accessible from my local machine.

I'd like to manually create a port forwarding rule to forward calls on <my-aws-host-ip>:<port> to <docker-local-ip>:<port> so that I can connect for remote debugging. I believe iptables is probably the right tool for this, but I am not familiar with its usage. How can I achieve this goal?

  • Why aren't you using docker's own port forwarding capabilities for this? docs.docker.com/engine/reference/run/#/expose-incoming-ports – Patrick Jul 16 '16 at 3:46
  • In Elastic Beanstalk you don't control the lifecycle of container startup, so although I can EXPORT <PORT> on arbitrarily many ports, Elastic Beanstalk won't map all those ports onto the host IP; they only map a single port. Hence the need to manually map the other ports from the host to the container. – dsw88 Jul 18 '16 at 16:27
  • Just configure EB: docs.aws.amazon.com/elasticbeanstalk/latest/dg/…. See the portMappings param. – Patrick Jul 18 '16 at 16:32
  • Unfortunately I'm stuck on the old V1 Dockerrun.aws.json for single-container mapping (moving isn't an option at the moment because of organizational reasons), and AWS will only map a single port onto the host from that file (the first), no matter how many you have configured. :( – dsw88 Jul 18 '16 at 16:34
0

Create a Dockerfile with no configuration such as:

//Dockerfile

FROM somePkg:1.2.3
EXPOSE 1337 8080 8081

This in mind, you will NOT have access via the PrivateIP, ONLY the PublicIP. You will need to get even more fancy for that, and AWS's ElasticBeanstalk already builds some iptables rules in your favor. It's up to you to get the docker container to map the ports if you're not using v2 of the Dockerrun.aws.json file.

Also remember AWS's ElasticBeanstalk automatically forwards the first port in the list to port 80.

So in this case it would be external_interface:80 -> docker_container:1337

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.