Flask Docker Image

Introduction

Please note use lowercase for all the folder names. In my case I have created a folder "DOCKER" on my folder where all my docker images will be created.

Go to /home/snk/dockers/

Create a directory with the application name for example allclaims

Place *.py , Dockerfile and Requirement.txt

 

Step 1 - Stop Docker Container (If Any)

docker container ps

Take the correct container id and stop it

docker container stop  Name_of_the_container

Remove the container 

docker container rm Name_of_the_container

Build the container using container build command

docker build -t name_of_the_image:latest .

Run the container & expose port to use it in the Nginx reverse proxy.

docker run -it -d -p 5000:5000 name_of_the_image

Step 2 - Proxy pass in Nginx server

Use the default site file, in case if you don't use the server blocking, else use the respective server file in Nginx server.

sudo nano /etc/nginx/sites-available/default

Add the location with application name and its corresponding dockers port and path as shown bellow.

        location /allclaims/ {
                proxy_pass   http://103.4.6.220:5000/;
        }

Restart the Nginx server to changes to reflect.

sudo systemctl reload nginx

 

Information 

Most of the time when you run docker images inside the proxy you might end up with improper CSS or site load, in that case always use  environment variable of APP_URL, check each application for more information on the same

 Example while running the docker use the following command along with run statement. 

" -e APP_URL=https://docker2.auto-boxe.com/book "