3

I'm facing an annoying problem with Docker using a php:7.4.12-apache-buster image and WordPress.

I mounted source code to Docker container and everything works properly except that after some minutes of inactivity first refresh of the host browser takes over 10s, subsequent refreshes are 290ms but again, after some inactivity minutes, the first request is slow and subsequent ones are fast.

I'm facing this for over a year trying to understand what happens, I saw some people saying that have a kind of sleep configuration on the container and others saying that it's a DNS problem but, I tried barely everything without success including docker-sync.

That's is my docker setup configuration files.

web.Dockerfile

FROM php:7.4.12-apache-buster
LABEL Name=app Version=1.0.0

RUN a2dissite 000-default
RUN rm /etc/apache2/sites-available/*.conf
ADD apache/project.conf /etc/apache2/sites-available

RUN mkdir /etc/apache2/ssl
COPY apache/ssl/* /etc/apache2/ssl/

RUN mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini

RUN a2enmod ssl
RUN a2enmod headers
RUN a2enmod rewrite

RUN mkdir -p /var/www/html/app
RUN mkdir -p /var/log/apache2/html/app
RUN chown -R www-data:www-data /var/www/html/app
RUN chown -R www-data:www-data /var/log/apache2/html/app

RUN a2ensite project
EXPOSE 80 443
RUN service apache2 stop

RUN apt-get update
RUN apt-get install -y libxml2-dev tzdata
RUN docker-php-ext-install mysqli
RUN docker-php-ext-install soap

ENV TZ=America/Sao_Paulo
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

db.Dockerfile

FROM mysql:latest

docker-compose.yml

version: "3.8"

services:
  http:
    volumes:
      - ./src:/var/www/html/app
    build:
      context: "./docker"
      dockerfile: "web.Dockerfile"
    ports:
      - 443:443
    depends_on:
      - db
  db:
    build:
      context: "./docker"
      dockerfile: "db.Dockerfile"
    restart: always
    volumes:
      - ./data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: 123456
      MYSQL_DATABASE: "app_development"
    ports:
      - 3306:3306
    security_opt:
      - seccomp:unconfined

All this is happening running Docker for Mac in OS X Mojave 10.14.6 on a local environment.

Any insight will be very helpful.

Best, Junio

Vitorino
  • 93
  • 1
  • 6
  • 1
    If you're trying to inject your entire application source code through bind mounts, it's a known issue that [Docker in MacOs is very slow](https://stackoverflow.com/questions/55951014/docker-in-macos-is-very-slow). That question lists a couple of workarounds. – David Maze Dec 13 '20 at 21:33

0 Answers0