I have a non-typical situation with docker-compose. I use only PHP 7.4 docker container for LEMP stack. In my configuration, I've defined port 9000 for PHP, and also I've used network_mode: 'host'. In this case, PHP can work with MySQL, but also can be accessible all over the world. If I comment #network_mode: 'host', PHP not accessible for everybody, but also can't work with MySQL. How can I use PHP with MySQL altogether, but will not be accessible for attackers? Thanks!
services:
php:
container_name: php7.4
restart: always
network_mode: 'host'
ports:
- "127.0.0.1:9000:9000"
build: ./images/php
volumes:
- /var/www/html:/var/www/html