私は、Web アプリをホストするために Docker コンテナーを使用しています。MySQL、Flask、Nginx の 3 つのメイン コンテナーがあります。最初の 2 つは期待どおりに動作し、後者は docker-compose の起動時にエラーが表示されないため、正常に動作しているようです。
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
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/
デプロイ後のコンテナとそれぞれのポート:
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
私は Nginx サーバーを初めて使用するので、これは初心者のエラーかもしれません。ホスト マシンの 80 ポートからのすべてのトラフィックを docker の 80 にリダイレクトしようとしています。これにより、トラフィックがソケット経由で WSGI コンテナーにリダイレクトされます。
私は次の Nginx 設定を使用しています (特に凝ったものではありません)。
server {
listen 80;
location / {
include uwsgi_params;
uwsgi_pass flask:8080;
}
}
ご覧のとおり、サーバーはポート 80 でリッスンし、すべてのトラフィックをソケット経由でuwsgi_pass flask:8080;
アプリをホストしている WSGI コンテナーにリダイレクトします。
しかし、ブラウザに 127.0.0.1:80 または 0.0.0.0:80 と入力すると、接続が拒否されます。ファイアウォールは導入していないので、ポート 80 がダウンしていても問題はないと思われます。
これは私の app.ini 構成ファイルで、初期化とデプロイメントのパラメータが指定されています。
[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
さらに、docker-compose.yml も含めます (役立つと思います):
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"
誰か助けてくれませんか?
アップデート
Wireshark を使用してループバック インターフェイスをスキャンし、0.0.0.0:80 へのサーバーの応答を確認しました (ポート 80 に何らかの問題があると思われます)。次のペイロードが返されました。