繁体   English   中英

只有 nginx 默认页面显示在 Docker 容器中

[英]Only nginx default page showing in Docker container

我创建了一个 Flask 应用程序,它在 Flask 开发服务器上运行良好。

现在,我正在尝试在 docker 容器中运行此 Flask 应用程序。 虽然可以成功构建容器(使用docker build. -t minex_image )并运行(使用docker run --name minex_container -p 80:80 minex_image ),但应用程序的主页没有显示。 相反,我在打开localhost:80时只得到 nginx 默认页面。

我已经尝试将套接字权限设置为666 ,但无济于事。 任何帮助都感激不尽。

这是来自 nginx 和 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)

附录 - 申请文件

应用程序文件夹包含以下文件:

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

重要的配置文件可以在下面找到。 我使用了这里那里的示例来生成配置文件。

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

我找到了 nginx 配置不正确的原因。 在 Dockerfile 中,我将 nginx 配置文件复制到文件夹/etc/nginx 之后,我通过apt-get安装了 nginx,这导致我的配置被默认配置文件覆盖。

因此,需要通过将COPY nginx.conf /etc/nginx apt-get后面来纠正 Dockerfile 。

更正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"]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM