title: Docker containers linked but mysql cannot be connected to
body: <p>I am quite new to docker and have been battling two days to get my system going. My compose file creates nginx, php-fpm, mysql and phpmyadmin containers. I can ping all containers from each other. But when I try installing anything from my mounted public_html volume into the database (like installing an app that needs to create tables in database), the app simply cannot connect to the database. I have made sure over and over credentials are correct. For the life of me I don't know where I'm going wrong. Any help would be greatly appreciated. I include my compose file below:</p>
  
  <pre><code>version: '3'
  services:   
  www:
  container_name: site1-www
  image: nginx:1.13.7-alpine
  expose:
    - "80"
  ports: 
    - 8001:80
  networks:
    datacentre:
      aliases:
        - site1www  
  env_file:
    - ".env"
  environment:
    - NGINX_HOST=localhost
  volumes:
    - /mnt/www/site1.test/public_html:/usr/share/nginx/html/
    - 
  /mnt/www/site1.test/conf/default.conf:/etc/nginx/conf.d/default.conf
  depends_on:
    - db
  links
    - db
  
  phpfpm:
  build: ./phpfpm
  container_name: site1-phpfpm
  networks:
    datacentre:
      aliases:
        - site1php
  volumes:
    - /mnt/www/site1.test/public_html:/usr/share/nginx/html
    - /mnt/www/site1.test/conf/php.ini:/usr/local/etc/php/php.ini
  depends_on:
    - db
  links
    - db
  
  db:
  container_name: site1-db
  image: mariadb:10.3.2
  ports:
    - 3400:3306  
  env_file:
    - ".env"
  environment:
    - MYSQL_DATABASE=test1db
    - MYSQL_ROOT_PASSWORD=password
    - MYSQL_USER=test1user
    - MYSQL_PASSWORD=password
  networks:
    datacentre:
      aliases:
        - site1db
  volumes:
    - /mnt/dbdata:/var/lib/mysql
  
  dbadmin:
  image: phpmyadmin/phpmyadmin:latest
  container_name: site1-dbadmin
  ports:
    - 8000:80
  networks:
    datacentre:
      aliases:
        - site1dbadmin
  environment:
    - PMA_ARBITRARY=1
    - PMA_HOST=mysql
  depends_on:
    - db
  links
    - db
  
  networks:
    datacentre:
      external:
        name: datacentre_net
  </code></pre>