0

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.

tsm
  • 419
  • 4
  • 11
  • Do you use ECS for the deployment? – Marcin May 18 '20 at 02:49
  • I don't have a task definition. I created my app using docker-machine create --driver amazonec2 . I am just hosting it as a personal project. I am going to use ECS later but right now its more makeshift. – tsm May 18 '20 at 02:50

1 Answers1

1

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;
   }
}
Ryan.Bartsch
  • 3,698
  • 1
  • 26
  • 52
  • Thanks for the answer Ryan. I am currently looking into this solution. Should I create a separate service in my docker-compose or just use the same Dockerfile? – tsm May 18 '20 at 04:56
  • If you go with the first option (which is probably easier), you just need to specify the port bindings for your existing service - see https://docs.docker.com/compose/reference/port/ If you go with the nginx option, yes - you'll need a separate service in your docker-compose. – Ryan.Bartsch May 18 '20 at 05:09
  • ^^ that being said, there are ways to have multiple programs running in a single docker container e.g. nginx and your mern app (see https://stackoverflow.com/questions/19948149/can-i-run-multiple-programs-in-a-docker-container), but it's probably not recommended. – Ryan.Bartsch May 18 '20 at 05:26
  • Thanks again. I am going to try your first solution as I am having trouble configuring nginx to serve my app. Can I just specify the port mapping in my docker-compose ie port: -80:3000 or should I just follow the steps you outlined? – tsm May 18 '20 at 05:40
  • ^^ yes - just specify the port mapping as you've said :) – Ryan.Bartsch May 18 '20 at 05:41
  • 1
    It works! Thank you Ryan. I really appreciate your help. I wanted to get nginx to work but the first solution was great. I didn't make the connection that port 80 is just like / ! – tsm May 18 '20 at 06:20