I'm using docker-compose and now have two docker containers - one is a nginx webserver, whereas the other one is ubuntu with Python uwsgi and Flask.
As I know, the best way to connect nginx and uWSGI is done by sharing a *.sock file between them and pass the requests into the file (And that what I do in older projects where I did not use dockers).
I'm wondering how can I share the sock file between the dockers in order to enable the communication between them?
And at all.. I'm wondering if this scenario of two containers - one for nginx and one for the Flask framework and uWSGI - is best practice and right to do.
Thanks
You don't need to share the sock file with different docker container.
The simple solution is share the socket port between dockers.
In the uwsgi file need to add socket=:3000
.
[uwsgi]
master=true
chdir=.
module=flaskapp
harakiri=60
callable=app
thunder-lock=true
socket=:3000
workers=12
threads=4
chmod-socket=666
vacuum=true
die-on-term=true
pidfile=uwsgi.pid
max-requests=5000
post-buffering=65536
post-buffering-bufsize=524288
the define the nginx conf. the uwsgi_pass
section flask:3000
means (docker server name):(docker expose port).
server {
listen 80;
charset utf-8;
client_max_body_size 20M;
location / {
try_files $uri @slack;
}
location @slack {
include uwsgi_params;
uwsgi_pass flask:3000;
uwsgi_read_timeout 60s;
uwsgi_send_timeout 60s;
uwsgi_connect_timeout 60s;
}
}
In docker-compose file:
nginx:
container_name: nginx
build:
context: .
dockerfile: ./Dockerfile-Nginx
ports:
- "80:80"
depends_on:
- flask
flask:
tty: true
container_name: flask
build:
context: .
dockerfile: ./Dockerfile
expose:
- "3000"
command: uwsgi --ini ./uwsgi.ini
So just let the docker run one process for each docker container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With