Home > Software engineering >  Only nginx default page showing in Docker container
Only nginx default page showing in Docker container

Time:11-27

I created a Flask app that runs fine with the Flask development server.

Now, I am trying to run this Flask app inside a docker container. While the container can successfully be built (with docker build . -t minex_image) and run (with docker run --name minex_container -p 80:80 minex_image), the application' s homepage doesn't show up. Instead, I only get the nginx default page when opening localhost:80.

I already tried setting the socket permissions to 666, but to no avail. Any help will be much appreciated.

Here is the log from nginx and uWSGI:

Starting nginx: nginx.

[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.17.1 (64bit) on [Fri Nov 19 15:28:04 2021] ***
compiled with version: 8.3.0 on 19 November 2021 15:26:21
os: Linux-5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020
nodename: a551630c2d9e
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /srv/minexample_app
detected binary path: /usr/local/bin/uwsgi
setgid() to 33
setuid() to 33
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.socket fd 3
Python version: 3.7.4 (default, Oct 17 2019, 05:59:21) [GCC 8.3.0]

*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x55ce21285920
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 437520 bytes (427 KB) for 5 cores

*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x55ce21285920 pid: 25 (default app)

*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 25)
spawned uWSGI worker 1 (pid: 28, cores: 1)
spawned uWSGI worker 2 (pid: 29, cores: 1)
spawned uWSGI worker 3 (pid: 30, cores: 1)
spawned uWSGI worker 4 (pid: 31, cores: 1)
spawned uWSGI worker 5 (pid: 32, cores: 1)

Appendix - Application files

The application folder contains the following files:

app
|__src
|  |__app.py
|  |__templates
|     |__home.html
|__Dockerfile
|__nginx.conf
|__requirements.txt
|__start.sh
|__uwsgi.ini

The important configuration files can be found below. I used the examples from here and there in order to generate the config-files.

Dockerfile

#Download Python from DockerHub and use it
FROM python:3.7.4
#Set the working directory in the Docker container
WORKDIR /srv/minexample_app
#Copy the configuration files to the working directory
COPY requirements.txt .
COPY start.sh .
COPY uwsgi.ini .
#Copy the Flask app code to the working directory
COPY src/ .
#Copy nginx configuration file to the nginx folder
COPY nginx.conf /etc/nginx
#Install nginx web server
RUN apt-get clean \
    && apt-get -y update
RUN apt-get -y install nginx \
    && apt-get -y install python3-dev \
    && apt-get -y install build-essential
#Install the dependencies
RUN pip install -r requirements.txt --src /usr/local/src
#Run the container
RUN chmod  x ./start.sh
CMD ["./start.sh"]

start.sh

#!/usr/bin/env bash
service nginx start
uwsgi --ini uwsgi.ini

CodePudding user response:

I found the reason for the incorrect nginx configuration. In the Dockerfile, I copied the nginx configuration file to the folder /etc/nginx. After that, I installed nginx via apt-get, which caused my configuration to be overwritten by the default configuration file.

Thus, the Dockerfile needed to be corrected by moving the COPY nginx.conf /etc/nginx behind the apt-get.

Corrected Dockerfile

#Download Python from DockerHub and use it
FROM python:3.7.4
#Set the working directory in the Docker container
WORKDIR /srv/minexample_app
#Copy the configuration files to the working directory
COPY requirements.txt .
COPY start.sh .
COPY uwsgi.ini .
#Copy the Flask app code to the working directory
COPY src/ .

#Install nginx web server
RUN apt-get clean \
    && apt-get -y update
RUN apt-get -y install nginx \
    && apt-get -y install python3-dev \
    && apt-get -y install build-essential
#Install the dependencies
RUN pip install -r requirements.txt --src /usr/local/src

#Copy nginx configuration file to the nginx folder
COPY nginx.conf /etc/nginx
#Run the container
RUN chmod  x ./start.sh
CMD ["./start.sh"]
  • Related