Docker LEMP setup - The right way, but how?

Hi,

I’m a beginner and trying to create separate containers for each service, viz.
nginx:alpine
php-fpm
mariadb
phpmyadmin


I've separate Dockerfiles for the above and now I'm creating an image using the following command:

docker-compose up -d --build

docker-compose.yml

version: '3.7'

services:
  php-fpm:
    build:
      context: ./php-fpm
    volumes:
      - ../src:/var/www
      
  nginx:
    build:
      context: ./nginx
    volumes:
      - ../src:/var/www
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/sites/:/etc/nginx/sites-available
      - ./nginx/conf.d/:/etc/nginx/conf.d
    ports:
      - "80:80"
      - "443:443"
    depends_on: 
      - php-fpm
    external_links:
      - mariadb:mariadb
      - phpmyadmin:phpmyadmin

  mariadb:
    build:
      context: ./mariadb
    environment:
      - MYSQL_DATABASE=mymariadb
      - MYSQL_USER=myuser
      - MYSQL_PASSWORD=
      - MYSQL_ROOT_PASSWORD=
      - MYSQL_ALLOW_EMPTY_PASSWORD=1
    volumes:
      - "../database/mariadb:/var/lib/mysql"

  phpmyadmin:
    build:
      context: ./phpmyadmin
    ports:
      - "8080:80"
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOST=mariadb
    external_links: 
      - mariadb:mariadb

Output of the above:

Building php-fpm
Step 1/3 : FROM php:fpm-alpine
 ---> bc87acb9f634
Step 2/3 : CMD ["php-fpm"]
 ---> Using cache
 ---> 64023a1f111e
Step 3/3 : EXPOSE 9000
 ---> Using cache
 ---> 4b00f348534d

Successfully built 4b00f348534d
Successfully tagged docker_php-fpm:latest
Building nginx
Step 1/3 : FROM nginx:alpine
 ---> dd025cdfe837
Step 2/3 : CMD ["nginx"]
 ---> Using cache
 ---> 5b5ac4607316
Step 3/3 : EXPOSE 80 443
 ---> Using cache
 ---> b092be086dc0

Successfully built b092be086dc0
Successfully tagged docker_nginx:latest
Building mariadb
Step 1/4 : FROM mariadb:latest
 ---> e07bb20373d8
Step 2/4 : RUN ["apt-get", "update"]
 ---> Using cache
 ---> d8f4d5b1b71f
Step 3/4 : CMD ["mysqld"]
 ---> Using cache
 ---> 3a208062cbcd
Step 4/4 : EXPOSE 3306
 ---> Using cache
 ---> aff013451087

Successfully built aff013451087
Successfully tagged docker_mariadb:latest
Building phpmyadmin
Step 1/3 : FROM phpmyadmin/phpmyadmin
 ---> c6ba363e7c9b
Step 2/3 : CMD ["phpmyadmin"]
 ---> Using cache
 ---> 43356e17ba47
Step 3/3 : EXPOSE 8080
 ---> Using cache
 ---> d89c61f473e2

Successfully built d89c61f473e2
Successfully tagged docker_phpmyadmin:latest
Recreating docker_phpmyadmin_1 ... done
Recreating docker_php-fpm_1    ... done
Recreating docker_mariadb_1    ... done
Recreating docker_nginx_1      ... done

When I run the command: $ docker-compose ps
I get the following output:

Name                      Command                     State          Ports                  
------------------------------------------------------------------------------------
docker_mariadb_1     docker-entrypoint.sh mysqld      Exit 1                                             
docker_nginx_1       nginx                            Up        0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
docker_php-fpm_1     docker-php-entrypoint php-fpm    Up        9000/tcp                                
docker_phpmyadmin_1  /run.sh phpmyadmin               Exit 127  

Question:
1. Is my above approach and method correct?
2. Why is my mariadb and phpmyadmin exiting?


Apologies for the bad formatting and hope my query is clear?