How to make Flask in a Docker Container my main web site with NGINX

November 18, 2019 243 views
Docker Nginx

I followed the instructions here. https://www.digitalocean.com/community/tutorials/how-to-build-and-deploy-a-flask-application-using-docker-on-ubuntu-18-04 I’m trying to get my website to use NGINX and have a Docker Container serving my Flask Application. It is working, but it is on port 56733. I’m trying to have the Flask App served whenever anyone visits my web page. Could I just change the code below from start.sh

#!/bin/bash
app="docker.test"
docker build -t ${app} .
docker run -d -p **56733**:80 \
  --name=${app} \
  -v $PWD:/app ${app}

to

#!/bin/bash
app="docker.test"
docker build -t ${app} .
docker run -d -p **80**:80 \
  --name=${app} \
  -v $PWD:/app ${app}

I’m a noob at this and am doing this to learn more about Docker, Flask and NGINX. If anyone has any resources which explain NGINX well or deploying Docker on NGINX that would be greatly appreciated. I’ve been googling, but haven’t found the resources I’ve locate very helpful.

#!/bin/bash
app="docker.test"
docker build -t ${app} .
docker run -d -p **56733**:80 \
  --name=${app} \
  -v $PWD:/app ${app}

to

#!/bin/bash
app="docker.test"
docker build -t ${app} .
docker run -d -p **80**:80 \
  --name=${app} \
  -v $PWD:/app ${app}

I’m a noob at this and am doing this to learn more about Docker, Flask and NGINX. If anyone has any resources which explain NGINX well or deploying Docker on NGINX that would be greatly appreciated. I’ve been googling, but haven’t found the resources I’ve locate very helpful.

1 Answer

Yes, it would work if you change the port from 56733 to 80, that way if you visit your IP or your page directly from the browser you would not have to specify a port after it, as port 80 would be bound on the host.

However, I think that a better approach would be to use Nginx as a reverse proxy and pass the traffic from port 80 and port 443 to the 56733 port. You could follow the steps on how to configure Nginx for your docker here:

https://www.thepolyglotdeveloper.com/2017/03/nginx-reverse-proxy-containerized-docker-applications/

Have another answer? Share your knowledge.