Docker Community Forums

Share and learn in the Docker community.

Website with Shopping and Login system split into different containers

Hi community,

I have created a website as school project for selling coffee for instance.
I created a landing page which is in it’s own container. In addition I have a webserver container running NGINX, a mysql database container and a phpmyadmin container to edit the database easier. Now I want to add for instance a Log-In system which should run in its own container communicating with the landing page container.

My question now is, how I could implement this?
For better understanding I add my docker-compose.yml file, default.conf file and .env file.

docker-compose.yml

version: '3'
services:
    web:
        build: ./nginx/
        container_name: nginx-container
        ports:
            - "80:80"
        #environment:
         # - NGINX_HOST=${NGINX_HOST}
        links:
            - php
        volumes_from: 
            - app-data
      
    php:
        build: ./php/
        container_name: php-container
        expose:
            - "9000"
        links: 
            - mysql
        volumes_from:
            - app-data

    app-data:
        image: php:7.0-fpm
        container_name: app-data-container
        volumes:
            - ./www/html/:/var/www/html
            #- ./www/images/:/var/www/images
            - "./nginx/default.conf:/etc/nginx/conf.d/default.conf"
        command: "true"

    mysql:
        image: mysql:5.7
        container_name: mysql-container
        volumes_from:
            - mysql-data
        env_file:
            - ".env"
        environment:
            - MYSQL_DATABASE=${MYSQL_DATABASE}
            - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} 
            - MYSQL_USER=${MYSQL_USER}
            - MYSQL_PASSWORD=${MYSQL_PASSWORD}
        ports:
            - "3306:3306"
        
    mysql-data:
        image: mysql:5.7
        container_name: mysql-data-container
        volumes:
            - /var/lib/mysql
        command: "true"

    myadmin:
        image: phpmyadmin/phpmyadmin
        container_name: phpmyadmin
        ports:
            - "8080:80"
        environment:
            - PMA_ARBITRARY=1
            - PMA_HOST=192.168.2.110
        depends_on:
            - mysql

default.conf

server {  

     listen 80 default_server;  
     root /var/www/html;  
     index index.html index.php;  

     charset utf-8;  

     location / {  
      try_files $uri $uri/ /index.php?$query_string;  
     }  

     location = /favicon.ico { access_log off; log_not_found off; }  
     location = /robots.txt { access_log off; log_not_found off; }  

     access_log off;  
     error_log /var/log/nginx/error.log error;  

     sendfile off;  

     client_max_body_size 100m;  

     location ~ .php$ {  
      fastcgi_split_path_info ^(.+.php)(/.+)$;  
      fastcgi_pass php:9000;  
      fastcgi_index index.php;  
      include fastcgi_params;  
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
      fastcgi_intercept_errors off;  
      fastcgi_buffer_size 16k;  
      fastcgi_buffers 4 16k;  
    }  

     location ~ /.ht {  
      deny all;  
     }  
    } 

.env

#!/usr/bin/env bash

# See https://docs.docker.com/compose/environment-variables/#the-env-file

# Nginx
NGINX_HOST=localhost

# PHP

# See https://hub.docker.com/r/nanoninja/php-fpm/tags/
PHP_VERSION=latest

# MySQL
MYSQL_VERSION=8.0.21
MYSQL_HOST=mysql
MYSQL_DATABASE=mydb
MYSQL_ROOT_USER=root
MYSQL_ROOT_PASSWORD=root
MYSQL_USER=dev
MYSQL_PASSWORD=dev