Docker: Connection PHP/Apache --> MySQL slow

2

I would like to ask for help on my Docker installation, because I can't fix it. I have read a lot about slow Docker containers but all things I tried don't help.

When I browser the phpmyadmin UI it feels quite fast and tables/edits load quickly. But when I load my CMS it is slow (takes about 3 to 5 seconds) to load. Even the AJAX requests inside the CMS are slow. The CMS is very fast on my production webserver, in fact it is still faster than my local Docker installation. I guess there is a problem when connection form the webserver to the MySQL server. Had read about DNS problems with this, but couldn't find a way to solve it.

What I tried:

  • use 'link' to connect the containers
  • use 'network_mode: host'
  • use 'networks: - mylocalnetwork' and 'networks: mylocalnetwork: driver: bridge'
  • put the MySQL data inside the container (not on the host OS)
  • changed ports
  • some other, can't remember

Docker Version 2.0.0.0-mac81 (29211) (Engine: 18.09.0)

Docker-compose.yml:

version: '3'
services:
  db:
    image: mysql:5.7
    volumes:
      - "./.data/db:/var/lib/mysql"
    environment:
      MYSQL_DATABASE: devtest
      MYSQL_USER: root
      MYSQL_PASSWORD: pass
      MYSQL_ROOT_PASSWORD: pass
    ports:
      - "9906:3306"
    network_mode: "host"
  web:
    build: .
    depends_on:
      - db
    volumes:
      - /path/to/www:/var/www/html
    ports:
      - "8100:80"
      tty: true
    stdin_open: true
    network_mode: "host"
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    depends_on:
    - db
    external_links:
    - db:mysql
    ports:
    - "9191:80"
    environment:
        PMA_HOST: db
        MYSQL_USER: root
        MYSQL_ROOT_PASSWORD: pass
        MYSQL_PASSWORD: pass
    network_mode: "host"

Dockerfile

FROM php:7.2.2-apache

RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install mysqli

#RUN apt-get update
#RUN apt-get install nano

RUN usermod -u 1000 www-data

RUN a2enmod rewrite
RUN a2enmod headers
RUN a2enmod expires

=== EDIT From Docker App Advanced Settings: CPU: 4 RAM: 2 GB SAWP 1 GB An exported SQL file is ~ 450 KB CMS says allocated memory peak is 19.56 MB

Keysmith

Posted 2019-01-07T13:47:32.950

Reputation: 21

Hi Keysmith. We'll need more info on your setup to give you a good idea of what might be happening. please can you provide the capabilities of the docker instance (CPU, RAM availablity etc), and the size of the relevant databases. Also, is the same slowness across all browsers? – Stese – 2019-01-07T14:15:10.537

Thanks. I have updated my post above. And yes, slow on multiple browsers (incognito mode) – Keysmith – 2019-01-07T15:24:15.383

Additional information request. Post on pastebin.com and share the links. RAM size of your MySQL Host server A) complete (not edited) my.cnf or my.ini
Text results of: B) SHOW GLOBAL STATUS; after minimum 24 hours UPTIME C) SHOW GLOBAL VARIABLES; D) SHOW FULL PROCESSLIST; AND Optional very helpful information, if available includes - htop OR top OR mytop for most active apps, ulimit -a for a linux/unix list of limits, iostat -xm 5 3 for IOPS by device and core/cpu count, df -h for a linux/unix free space list by device, for server tuning analysis.
– Wilson Hauck – 2019-01-19T18:38:24.453

Have exactly the same problem. Using my local installed MariaDB is fast but using the container is extremely slow. I read that because of MacOS <-> Linux VM the file transport is slow, so I tried using some caching methods but without success. – muuvmuuv – 2019-08-15T12:36:22.227

No answers