Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Painful slow docker PHP setup on Windows

Tags:

I run Docker for Windows with Hyper-V, 4 cores and 8GB RAM but page loads of my PHP project are in the order of 40 seconds per page.

My setup uses self signed certificates, but I think the problem is related to something else.

During my docker build I get the following warning:

---> Running in 46329f96a79f Restarting Apache httpd web server: apache2[Mon Jun 11 09:17:26.151516 2018] [ssl:warn] [pid 23] AH01906: localhost:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?) [Mon Jun 11 09:17:26.151605 2018] [ssl:warn] [pid 23] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name

Since non-https pages load also very slow, I think it is something else.

My Docker file is as follows

FROM php:5.6-apache
COPY server.crt /etc/apache2/ssl/server.crt
COPY server.key /etc/apache2/ssl/server.key
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN apt-get update &&\
apt-get install --no-install-recommends --assume-yes --quiet ca-certificates 
curl git &&\
rm -rf /var/lib/apt/lists/*
RUN curl -Lsf 'https://storage.googleapis.com/golang/go1.8.3.linux- 
amd64.tar.gz' | tar -C '/usr/local' -xvzf -
ENV PATH /usr/local/go/bin:$PATH
RUN go get github.com/mailhog/mhsendmail
RUN cp /root/go/bin/mhsendmail /usr/bin/mhsendmail
RUN echo 'sendmail_path = /usr/bin/mhsendmail --smtp-addr mailhog:1025' > 
/usr/local/etc/php/php.ini
COPY ./ /var/www/html/
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN a2enmod rewrite
RUN a2enmod ssl
COPY dev.conf /etc/apache2/sites-enabled/dev.conf
RUN service apache2 restart
EXPOSE 80
EXPOSE 443

When I click a link, it shows Waiting... in de browser bar for ~40sec, but showing the page content itself is pretty fast

Could it be a DNS issue?

like image 694
user3411864 Avatar asked Jun 11 '18 08:06

user3411864


1 Answers

I will share with you my docker settings using PHP + Redis + MySQL + Nginx, see if it will be useful for you!

My Dockerfile

FROM php:7.1-fpm

RUN apt-get update
RUN apt-get install -y zlib1g-dev \
    libjpeg-dev \
    libpng-dev \
    libfreetype6-dev

# Add Microsoft repo for Microsoft ODBC Driver 13 for Linux
RUN apt-get update && apt-get install -y \
    apt-transport-https \
    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update

# Install Dependencies
RUN ACCEPT_EULA=Y apt-get install -y \
    unixodbc \
    unixodbc-dev \
    libgss3 \
    odbcinst \
    msodbcsql \
    locales \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen

RUN pecl install pdo_sqlsrv-4.1.8preview sqlsrv-4.1.8preview \
    && docker-php-ext-enable pdo_sqlsrv sqlsrv

RUN ln -s /usr/lib/x86_64-linux-gnu/libsybdb.a /usr/lib/

RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install zip

RUN mkdir -p /code
ENV HOME=/code
WORKDIR $HOME

USER root
COPY ./ $HOME

In this docker file has an SQLServer connection plugin too (I have many projects that I have integrated with it).

Now my docker-compose.yml

web:
    container_name: your_web_container_name
    image: nginx
    ports:
        - "80:80"
    volumes:
        - ./:/code
        - ./host.conf:/etc/nginx/conf.d/default.conf
    links:
        - php:php
redis:
    container_name: your_redis_container_name
    image: redis
php:
    container_name: your_php_container_name
    build: ./
    dockerfile: ./Dockerfile
    volumes:
        - ./:/code
    links:
        - db
        - redis
db:
    container_name: your_database_container_name
    image: mysql:5.6
    volumes:
        - /var/lib/mysql
    ports:
        - "3306:3306"
    environment:
        - MYSQL_USER=docker
        - MYSQL_DATABASE=docker
        - MYSQL_ROOT_PASSWORD=docker
        - MYSQL_PASSWORD=docker

The default.conf of the nginx:

server {
    listen 80 default_server;
    root /var/www/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm 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; }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9001;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

I hope it could be helpful to you.

like image 180
Fabio William Conceição Avatar answered Oct 14 '22 22:10

Fabio William Conceição