skip to Main Content

I’m new to Docker and I recently created an image containing multiple containers using PHP 7.4, MySQL, phpMyAdmin, and Redis.

My containers are working fine, but I’ve noticed that my Laravel site is very slow to load. I’m using WSL on Windows 11 Pro, and I don’t mount the “vendor” directory of Laravel via WSL because I read online that it can cause performance issues.

I’ve created a volume for the “vendor” directory and executed the “composer update” command directly inside the PHP container. Everything seems to be working fine, but the site is still very slow.

I would like to ask if someone could take a look at my Dockerfile and docker-compose files and possibly identify the cause of this slowness.

Thank you sincerely for your valuable assistance.

docker-compose.yml

version: '3'

services:
  php:
    image: php:7.4-apache
    ports:
      - 80:80
      - 443:443
    volumes:
      - /mnt/c/dev/web:/var/www/html/
      - /var/www/html/vendor
    networks:
      - my_network
    depends_on:
      - mysql
      - redis
  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: 123456
      MYSQL_DATABASE: myDatabase
      MYSQL_USER: myDatabase
      MYSQL_PASSWORD: 123456
    networks:
      - my_network
    volumes:
      - /mnt/c/dev/myDatabase/docker/sql:/docker-entrypoint-initdb.d

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - 8080:80
    environment:
      PMA_HOST: mysql
    networks:
      - my_network
    depends_on:
      - mysql

  redis:
    image: redis:latest
    networks:
      - my_network

networks:
  my_network:

Dockerfile

# Use a base image with Apache and PHP 7.4
FROM php:7.4-apache

RUN export COMPOSER_ALLOW_SUPERUSER=1;

RUN apt-get update && apt-get install -y 
    libzip-dev 
    libmagickwand-dev 
    libfreetype6-dev 
    libjpeg62-turbo-dev 
    libpng-dev 
    libxml2-dev 
    libcurl4-openssl-dev 
    libonig-dev 
    libssl-dev 
    openssl 
    nano 
    locate 
    supervisor 
    openssh-server 
    git 
    curl 
    libpng-dev 
    libonig-dev 
    libxml2-dev 
    libzip-dev 
    libicu-dev 
    && docker-php-ext-install zip 
    && docker-php-ext-configure intl 
    && docker-php-ext-install intl 
    && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd


RUN pecl uninstall imagick
RUN pecl install imagick && docker-php-ext-enable imagick

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY sites-available/apache2.conf /etc/apache2/apache2.conf
COPY sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf
COPY sites-available/default-ssl.conf /etc/apache2/sites-available/default-ssl.conf
COPY sites-available/web.conf /etc/apache2/sites-available/web.conf

RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor
COPY supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf


RUN a2ensite web.conf

RUN a2enmod ssl
RUN a2enmod rewrite

COPY ssl/certificat.crt /etc/ssl/certs/apache-selfsigned.crt
COPY ssl/private.key /etc/ssl/private/apache-selfsigned.key

COPY vendor_default /var/www/html/vendor

EXPOSE 80
EXPOSE 443
EXPOSE 22

RUN updatedb


# Change permissions for the "vendor" directory
RUN chown -R www-data:www-data /var/www/html/vendor
RUN chmod -R 755 /var/www/html/vendor

CMD ["apache2-foreground"]
CMD ["/usr/bin/supervisord"]

My containers are working fine, but I’ve noticed that my Laravel site is very slow to load. I’m using WSL on Windows 11 Pro, and I don’t mount the “vendor” directory of Laravel via WSL because I read online that it can cause performance issues.

2

Answers


  1. I am having the same issue in my mysql (or mariadb) docker container running over WSL 2 (Ubuntu) on Windows environment. I keep MySQL container’s data/volume inside a path belongs to WSL 2 (eg. /home/data/mysql) but still get very low performance on connection and queries.

    I’ve noticed that a mysql client on windows side works very fast, but mysql related requests over Laravel are very slow, takes 7-10 secs each page to load.

    Login or Signup to reply.
  2. It may be due to network.

    There are a couple of bugs reported. Here are some links:

    Very slow network speed on WSL2 · Issue #4901

    Very slow network speeds #8171 – microsoft/WSL

    low internet speed in WSL 2

    WSL 2 — How To Fix Download Speed | by Chris Townsend

    Etc.

    Note that Windows 11 does not show virtual adapters so I had to apply the workaround using Powershell as Administrator:

     PS C:WINDOWSsystem32> Enable-NetAdapterLso -Name vEthernet* -IncludeHidden -IPv4
     PS C:WINDOWSsystem32> Enable-NetAdapterLso -Name vEthernet* -IncludeHidden -IPv6                                           PS 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search