I am new to deploying with docker. Actually, I am running my django app in my computer inside docker container, and it is running successfully on port localhost:8080. Then I pulled the code to remote server and started docker-compose up, and app is running successfully there as well. What I want to ask is that, how can I see the app with the help of ip adress of the server? For example, if the ip adress is 123.45.67.89 I think the app should be running in 123.45.67.89:8080 but it does not run there. How can I access to the app running in container in remote server?
P.S. I have not used nginx, should I use it?
2
Answers
Technically, it should work the way you did it, but maybe the port 8080 is not open to the outside world.
You could change the port mapping in your
docker-compose.yml
file:You can then access your app from 123.45.67.89, without any port specified since 80 is the default. If it doesn’t work, double check the ip address and your firewall rules.
However, using Nginx is almost always a good idea since the local web server you are using is not production ready (feature and security wise). I’ll not explain how to implement Nginx here because it’s a little bit off topic and there is a lot of resource available, but you should seriously consider it when you are deploying on a remote server.
The answer to this question greatly depends on where you are hosting your production application, and what type of services it provides you out of the box.
In general, production servers usually have some reverse proxy or application load balancer sitting in front of the containerized application(s).
Since you are starting with docker, and since I am assuming this is a personal or small scale app, I can recommend the following:
docker-compose.yml
file, and magically get a configured nginx proxy, without knowing anything about nginx.I am using this approach to deploy multiple personal websites to a single, low cost server.
An example
docker-compose.yml
might look like this:which basically tells the nginx-proxy to serve your app on both http://myapp.localhost and http://www.yoursite.com.
Of course, you will need to point your domains DNS to your digital ocean IP.