Docker local setup for WordPress keeps failing (Windows 11)

I have been struggling for literally 12 hours+ over the last two weeks with trying to get Docker to work as a local environment for developing a WordPress theme. I’ve gone through tutorial after tutorial but even copying the code EXACTLY from tutorials, I keep getting errors.

Where I seem to be having the problem is that I can get a setup working where it installs WordPress but doesn’t mount a volume to hold my local files, but the minute I try to add that, everything fails.

I am running Docker Desktop on a Windows 11 machine.

I’ve tried too many things to collect them all here, but these two summarize the key problem I’m having.

1) Using Code from WordPress Developer Resources

I’ve copied the code EXACTLY from https://developer.wordpress.com/2022/11/14/seetup-local-development-environment-for-wordpress/. I saved the file as a docker-compose.yml file, went to that directory from PowerShell and ran docker-compose up.

This one just straight up fails to launch at all. The Docker terminal produces a lengthy series of input/output errors but the first one appears to be: WordPress not found in /var/www/html.

For reference, the copied code is as follows:

version: "3.6"
services:
 wordpress:
   image: wordpress:latest
   container_name: wordpress
   volumes:
     - ./wordpress:/var/www/html
   environment:
     - WORDPRESS_DB_NAME=wordpress
     - WORDPRESS_TABLE_PREFIX=wp_
     - WORDPRESS_DB_HOST=db
     - WORDPRESS_DB_USER=root
     - WORDPRESS_DB_PASSWORD=password
   depends_on:
     - db
     - phpmyadmin
   restart: always
   ports:
     - 8080:80
 
 db:
   image: mariadb:latest
   container_name: db
   volumes:
     - db_data:/var/lib/mysql
   environment:
     - MYSQL_ROOT_PASSWORD=password
     - MYSQL_USER=root
     - MYSQL_PASSWORD=password
     - MYSQL_DATABASE=wordpress
   restart: always
 
 phpmyadmin:
   depends_on:
     - db
   image: phpmyadmin/phpmyadmin:latest
   container_name: phpmyadmin
   restart: always
   ports:
     - 8180:80
   environment:
     PMA_HOST: db
     MYSQL_ROOT_PASSWORD: password
 
volumes:
 db_data:

2) Using Code From the WordPress Image on Docker Hub

Again, copying code exactly from the official WordPress image on https://hub.docker.com/_/wordpress. This one does allow me to install WordPress but doesn’t create a directory for me to work with locally.

For reference, the copied code is:

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - wordpress:/var/www/html

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:

I will frankly admit that despite reading dozens of tutorials there’s a lot I don’t really ‘get’ about Docker. But that said, if I understand correctly, the volumes command has to do with mounting folders.

It seems like the major difference between the two files in #1 and 2 is this:

In #1, the WordPress service includes a direction for mounting a volume like this: - ./wordpress:/var/www/html. It also doesn’t list a volume named WordPress at the bottom of the page.

Sure enough, if I take the working code from #2 and make those two changes to it, I get another long series if input/output errors, although this one starts with:

WordPress not found in /var/www/html - copying now...
find: '.': Cannot allocate memory

I did do a search on that second error, but it seems to start running into people talking about kernels and memory management and I’m not entirely sure how to fix it.

I would really appreciate any help here! I know I may just be doing something stupid but it’s bewildering to copy code from reputable sources directly and have them fail like this.

In the directory where docker-composer.yaml is located, do you have a folder called wordpress that contains a wordpress installation?

Sorry, had to be back at my computer…

So baffling update–today I ran the first sequence again and it worked without the error, even without adding any WordPress files.

That being said, though–now both versions of copied code do now successfully install WordPress. However, neither of them appears to mount a volume I can use for saving my themes. I did try saving a copy of the wordpress folder you get when you download WordPress locally, but neither version of the code is serving the themes from it.

I know because both installs only show Twenty Twenty Three as an available theme, when I can see Twenty Twenty Two and Twenty Twenty One in the actual WordPress folders.

That said, I’ve found Laragon and it works fine so I’m giving up entirely on Docker for now (I needed to switch easily between PHP versions so XAMPP wasn’t a great fit–plus it crashes regularly on Windows 11 for some users like me). I’ve had nothing but problems with Docker from the word go.

I do appreciate your help though!

Docker works perfectly on any OS. So long as that OS is Linux :wink:

You do whatever works for you. Docker is very nice when it works but can give lots of headaches when it doesn’t. And I was only half kidding about Linux. In my experience that’s the only OS where it Just Works.

1 Like

I had gathered it was somewhat Linux-oriented since tutorials tend to include maybe a few paragraphs that include Windows instructions and then completely forget about it…

Thank you, though. I feel like learning programming encourages you to think that if your code isn’t working, you’ve probably made a mistake. That’s generally helpful until you run into something where the problem may not be something you can easily get at.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.