Search code examples
amazon-web-servicesamazon-route53docker-machinemern

How do I map a dockerized application hosted on aws from port 3000 to the root url?


I am currently using docker-machine to serve a mern app via port:3000.

Everything is working well - however my application is served at my-ip:3000. I don't want users to have to navigate to myurl.com:3000. What is the simplest solution to access the application from my-ip/ instead of my-ip:3000. I am using ec2 and route53 on aws.


Solution

  • docker-machine create --driver amazonec2 <my-app> just creates the EC2 VM named my-app.

    Assuming the EC2 VM is the default docker host for your docker commands; the easiest approach would be to bind the host port to the container port as follows docker run -p 80:3000 image-name when you run your container.

    Alternatively (and slightly more complex), you could host an NGINX container to listen on port 80 and proxy through to your app on port 3000 e.g.

    server {
       listen 80 default_server;
       listen [::]:80 default_server;
    
       location / {
          proxy_pass http://my-app:3000;
       }
    }