LEMP Stack with Docker Swarm and Docker Compose

Hello everybody,

i need some help and I hope that some of you can help me.
I downloaded all needed docker tools and setup some VM’s for following problem:
I want to create a LEMP Stack in Docker Container in a Docker swarm. I have 3 VM’s which are used as 3 nodes in the swarm. That is already working.
My problem is to distribute the mysql+nginx+php.
The nginx is running but PHP doesn’t work. I only could download the php file when i try to open the URL in the browser.
I use docker stack to deploy the containers about a docker-compose.yml file in the swarm. I don’t know what I’m doing wrong and I hope, that some of you could help me. The config files and the docker-compose.yml will follow.

Thank you a lot and sorry if something is wrong, it is my first post in this forum :confused:

My docker-compose.yml file looks following:

version: '3'

services:

nginx:

    image: nginx

    ports:

        - "8080:80"

    volumes:

        - ./code:/usr/share/nginx/html

        - ./site.conf:/etc/nginx/default.conf

        #- ./code:/var/www/html # I tried it with and without - no difference

 php:

    volumes:

        - ./code:/usr/share/nginx/html

        - ./php-fpm.conf:/etc/php/7.0/fpm/php-fpm.conf

    working_dir: /usr/share/nginx/html

    image: php:7-fpm

    environment:

        MYSQL_PASSWORD: Passw0rd

mysql:

    image: mysql:5.7

    volumes:

        - mysql-data:/var/lib/mysql

    environment:

        MYSQL_ROOT_PASSWORD: Passw0rd

    command: ['mysqld', '--character-set-server=utf8']

volumes:

   mysql-data:

I also have following config file for my nginx:

site.conf

server {

listen 80;

root /usr/share/nginx/html;

index index.html index.htm index.php



    location / {

        try_files $uri =404;

    }



    location ~ \.php$ {

        fastcgi_pass   test-php:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

    }

}

and this php-fpm.conf:

listen 0.0.0.0:9000

listen.allowed_clients = any