DEV Community

Cover image for Speed up your local WordPress development with Docker on Windows
Mạnh Đạt
Mạnh Đạt

Posted on

Speed up your local WordPress development with Docker on Windows

If you prefer watching the experiment, here is the video:

https://www.youtube.com/watch?v=SET8P5OeBfo

Most of us when beginning developing with Docker usually mount from a local path to a path inside the containers since it's the simplest solution. However, this simplicity comes with a cost:

Speed!

Especially when you are developing on Windows.

You see, Docker on Windows, despite all the efforts cannot compare to what it's like on Linux. I have my WP sites on Linux and it loads super fast.

From what I learn, mounting the local directory to a container on Windows can make app loads very slow, not just WordPress.

So, I decided to give it a try: move codes, database to a volume.

And guess what? Speed improved immensely.

The old setup

Here is the old setup:

version: '3.8'

services:
  wp:
    image: webdevops/php-apache:7.4
    container_name: wp
    restart: always
    volumes:
      - D:\Data\dev\wordpress\main\:/app
    ports:
      - 8888:80
  db:
    image: mariadb:10.5.3
    container_name: db
    restart: always
    volumes:      
      - ./db:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root

Enter fullscreen mode Exit fullscreen mode

You see the problem? Both db and the WordPress code are mounted from a local directory on the host machine. Thus, the site loads super slow.

The new setup

version: '3.8'

services:
  wp:
    image: webdevops/php-apache:7.4
    container_name: wp
    restart: always
    volumes:
      - wordpress:/app

    ports:
      - 8888:80
  db:
    image: mariadb:10.5.3
    container_name: db
    restart: always
    volumes:
      - db:/var/lib/mysql

    environment:
      MYSQL_ROOT_PASSWORD: root

volumes:
  db:
  wordpress:
Enter fullscreen mode Exit fullscreen mode

Now, I created two volumes, one for db and one for the WordPress code. Guess what? The site isn't slow anymore.

Give it a try

Top comments (5)

Collapse
 
walledmahmoud profile image
Walled Mahmoud Soliman • Edited

if this is my directory and inside the wordpress folder is the wordpress files

and my composer yml is :

version: '3.4'
services:
  wordpress:
    build:
      context: ./dockers/wordpress/
      target: dev
    command: [/start.sh]
    volumes:
      - ./wordpress/:/var/www/html
    env_file: ./dockers/wordpress/.env
    ports:
      - "8010:80"
    links:
      - mysql
    environment:
      LANG: C.UTF-8
  mysql:
    image: public.ecr.aws/docker/library/mysql:8.0
    command: mysqld --default-authentication-plugin=mysql_native_password
    platform: linux/amd64
    volumes:
      - ./dockers/mysql/:/etc/mysql/conf.d
    ports:
      - "3310:3306"
    environment:
      MYSQL_ROOT_PASSWORD: #
      MYSQL_DATABASE: #
      LANG: C.UTF-8

volumes:
  db:
Enter fullscreen mode Exit fullscreen mode

How i can apply your idea? I am stuck with it.

Thanks in advance.

Image description

Collapse
 
aguycoding profile image
Ben

nice, is it possible to "inspect/change/alter" the contents of that docker volume too?

Collapse
 
mlopezcoria profile image
Mauricio López Coria

Sorry but I don't get the difference.

Collapse
 
mathieu_clment_cbe37fb0e profile image
Mathieu Clément

Old version uses local directories on the host file system, new version uses Docker volumes.

Collapse
 
lukasz_l profile image
lukaszlatacz

thx its work :)