The main difference with other setups here is that this one is for development. This means you need to get easy access to the source code of themes and plugins. In order to do that, you only need to change one line from the official Docker guide to setup WordPress.

Original

The original is as follows. You will only need to change the volume part under wordpress to point /var/www/html to a host (local) directory like c: or d: or /home/ubuntu/temp.

version: "3.9"
    
services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - wordpress_data:/var/www/html
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
volumes:
  db_data: {}
  wordpress_data: {}

Modified Version

The modified version changes wordpress_data to point to a local directory for example in this case to /mnt/d/temp/wordpress. You will also need to remove it from volumes: in the last line.

version: "3.9"
    
services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - /mnt/d/temp/wordpress:/var/www/html
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
volumes:
  db_data: {}

Now if you run docker-compose up -d you should the see the following files in your directory:

If you are having trouble setting WSL on Windows feel free to check this post and if you would like to access Logs check out this post here on How To Access WordPress Logs From Docker.

Happy development! 🙂