Access an application that is hosted with docker-compose on other computers


I’m very new to docker and I’ve just managed to containerize an application that I want to host on my laptop so that other remote people can access this application.

What are my alternatives for granting remote people access?

I would optimally want to have a DNS-name pointing at my web-application but I’m not sure if I need to use something like AWS or Azure to host the application in the cloud, or if I can just use a IIS/Nginx-image in my docker-compose file and point remote people to an IP-address/DNS-name.

Thanks so much in advance

Best regards Isak

Use docker run -p or the Docker Compose ports: section to expose your application via a port on your host system. Set the DNS name to point at the host.

This is slightly inconvenient if you want to host a plain Web application and otherwise have the power to make work; you’d prefer to not have to qualify it with a specific port number. In that case you need some intermediary that can answer that DNS name on port 80/443 and forward it to the right port on the physical host. In AWS I’d use an ordinary load balancer for this; I think it’s also pretty common to set up nginx or another Web server to do host-based routing.

My two pieces of advice are to not try to give your container an independently-accessible IP address (you will wind up reinventing most of the Docker networking machinery by hand and probably hard-coding IP addresses, which invites trouble) and to not touch /etc/hosts anywhere at all (you said the magic words “DNS name” which is the right answer).

For AWS specifically, setting up an ordinary EC2 instance, installing Docker on it, publishing a port as normal, then setting up a load balancer in front of it and setting up a Route 53 DNS name to point at the load balancer is pretty routine. This is also the recommended setup for Amazon’s EC2 Container Service, but you don’t necessarily need to buy into ECS to do it.

Thanks for your answer!

So if I understand this correctly, I do not need to use AWS or Azure to grant people access to my application? Let’s say I have an ASP.NET Core backend, Angular frontend, and nginx. How would someone remotely access my application if I host it on my laptop via docker-compose up? Is it possible to point them at my ip-address?

I understand how the containers communicate with each-other but I don’t understand how when I publish a container on the host (my laptop), how other computers are able to access this port.

Pretend you weren’t using Docker and you were running these applications directly on your laptop. From the point of view of other computers it’s exactly the same.