skip to Main Content

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?

docker-compose.yml

2

Answers


  1. 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:

    ports:
        - "80":"8080"
    

    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.

    Login or Signup to reply.
  2. 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:

    1. If you are flexible in terms of hosting providers, try Digital Ocean. They are very developer friendly, and cost effective, at least until a certain scale point.
    2. Use the automated docker nginx-proxy. This tool lets you add a couple of lines to your 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:

    services:
      nginx:
        image: nginxproxy/nginx-proxy
        ports: ["${PORT:-80}:80"]
        restart: always
        volumes:
        - /var/run/docker.sock:/tmp/docker.sock:ro
        environment:
          DEFAULT_HOST: www.yoursite.com
    
      app:
        depends_on: [nginx]
        restart: always
        image: your/image
        environment:
          VIRTUAL_HOST: myapp.localhost,www.yoursite.com
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search