Estoy usando contenedores Docker para alojar una aplicación web. Tengo tres contenedores principales: MySQL, flask y Nginx. Los dos primeros funcionan como se esperaba y el último parece funcionar bien ya que no se muestra ningún error en el inicio de Docker-Compose.
Salida de inicialización del contenedor Nginx:
nginx | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx | 2022/04/07 13:09:13 [notice] 1#1: using the "epoll" event method
nginx | 2022/04/07 13:09:13 [notice] 1#1: nginx/1.21.6
nginx | 2022/04/07 13:09:13 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
nginx | 2022/04/07 13:09:13 [notice] 1#1: OS: Linux 4.19.130-boot2docker
nginx | 2022/04/07 13:09:13 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx | 2022/04/07 13:09:13 [notice] 1#1: start worker processes
nginx | 2022/04/07 13:09:13 [notice] 1#1: start worker process 21
Archivo acoplable Nginx
# Dockerfile-nginx
FROM nginx:latest
# Nginx will listen on this port
# EXPOSE 80
# Remove the default config file that
# /etc/nginx/nginx.conf includes
RUN rm /etc/nginx/conf.d/default.conf
# We copy the requirements file in order to install
# Python dependencies
COPY nginx.conf /etc/nginx/conf.d/
Contenedores después de su despliegue y sus respectivos puertos:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bffffcfe2f70 sc_server_nginx "/docker-entrypoint.…" 14 seconds ago Up 13 seconds 0.0.0.0:80->80/tcp nginx
a73d958c1407 sc_server_flask "uwsgi app.ini" 9 hours ago Up 9 hours 8080/tcp flask
d273db5f80ef mysql:5.7 "docker-entrypoint.s…" 21 hours ago Up 9 hours (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
Soy nuevo en el servidor Nginx, así que supongo que puede ser un error de novato. Estoy intentando redirigir todo el tráfico desde el puerto 80 de mi máquina host al puerto 80 de Docker, que redirige el tráfico al contenedor WSGI a través de un socket.
Estoy usando la siguiente configuración de Nginx (nada sofisticado, supongo):
server {
listen 80;
location / {
include uwsgi_params;
uwsgi_pass flask:8080;
}
}
Como puede ver, el servidor escucha en el puerto 80 y redirige todo el tráfico a través del socket uwsgi_pass flask:8080;
al contenedor WSGI que aloja la aplicación.
Sin embargo, cada vez que escribo 127.0.0.1:80 o 0.0.0.0:80 en mi navegador, se rechaza la conexión. No tengo ningún firewall implementado, así que supongo que no hay problema con que el puerto 80 esté inactivo.
Este es mi archivo de configuración app.ini, en el que se indican los parámetros de inicialización y despliegue:
[uwsgi]
wsgi-file = wsgi.py
; This is the name of the variable
; in our script that will be called
callable = app
; We use the port 8080 which we will
; then expose on our Dockerfile
socket = :8080
; Set uWSGI to start up 4 workers
processes = 4
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true
Además, también incluyo docker-compose.yml (supongo que puede ser útil):
docker-compose.yml
services:
flask:
build: ./flask
container_name: flask
restart: always
environment:
- APP_NAME=MyFlaskApp
- YOURAPPLICATION_SETTINGS=docker_config.py
expose:
- 8080
depends_on:
mysql:
condition: service_healthy
mysql:
image: mysql:5.7
container_name: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE:
MYSQL_USER:
MYSQL_PASSWORD:
volumes:
- ./db/init.sql:/data/application/init.sql
healthcheck:
test: mysql -u -p --database -e "show tables;"
interval: 3s
retries: 5
start_period: 30s
nginx:
build: ./nginx
container_name: nginx
restart: always
depends_on:
- mysql
- flask
ports:
- "80:80"
¿Alguien puede ayudar?
Actualizar
Utilicé Wireshark para escanear la interfaz de bucle invertido para ver la respuesta del servidor a 0.0.0.0:80 (sospecho que podría haber algún problema con el puerto 80) y obtengo la siguiente carga útil: