Seeking Help with Docker WordPress Issues: REST API, Loopback, and RSS Errors 😢

Hi everyone!

I’m using Docker on Windows 11 to develop websites locally, as I mentioned in my previous post here.

Here is my docker-compose.yml file:

services:
  db:
    image: mysql
    environment:
      MYSQL_DATABASE: wordpress_db
      MYSQL_USER: db_user
      MYSQL_PASSWORD: db_user_pass
      MYSQL_ROOT_PASSWORD: securepassword
    volumes:
      - db:/var/lib/mysql

  wordpress:
    image: wordpress:6.9.0-php8.5-apache
    ports:
     - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: wordpress_db
      WORDPRESS_DB_USER: db_user
      WORDPRESS_DB_PASSWORD: db_user_pass
    volumes:
     - wordpress:/var/www/html

volumes:
  wordpress:
  db:

The site is working just fine, however, I’m getting several errors on the Site Health tab. For example, it shows two critical errors:

1. REST API error:

The REST API encountered an error:

The REST API is one way that WordPress and other applications communicate with the server. For example, the block editor screen relies on the REST API to display and save your posts and pages.

When testing the REST API, an error was encountered:

REST API Endpoint: http://localhost:8080/wp-json/wp/v2/types/post?context=edit
REST API Response: (http_request_failed) cURL error 7: Failed to connect to localhost port 8080 after 0 ms: Could not connect to server

2. Loopback request error:

Your site could not complete a loopback request

Loopback requests are used to run scheduled events, and are also used by the built-in editors for themes and plugins to verify code stability.

The loopback request to your site failed, this means features relying on them are not currently working as expected.
Error: cURL error 7: Failed to connect to localhost port 8080 after 0 ms: Could not connect to server (http_request_failed)

Here is a screenshot:

I’m also getting the following error:

3. RSS error:
**RSS Error:** WP HTTP Error: cURL error 28: Connection timed out after 10002 milliseconds

Here is a screenshot:

I’ve tried several methods found online to solve these issues, but nothing has worked so far. The only thing that worked temporarily was changing the site link to host.docker.internal:8080 - ChatGPT suggested doing this, and it worked well for about a month. However, after I updated Docker, the site stopped responding, and I had to change the link back to localhost:8080 manually via sql command to get it working again.

Please help! :cry:

ChatGPT doesn’t care about your actual issue. It just generates some texts bsed on your input. If you want to use it ask questions that helps you understand the problem and then you can look for documentation or discussions on forums.

It likely recommended using host.dcker.intrnal because you wanted to access the site on port 8080, because that is what you can use in a web browser. But than the domain wil not work on the host. I don’t remember any time when that domain worked on the host, but I rarely use Windows I am not sure.

There is a URL you use to access the website, and Wordpress needs to know about that URL (if I remember correctly) to redirect you to the right URLs when needed, since redirection happens on the client side. The server just sends the header either in th HTTP response header or in a HTML header. At the same time, Wordpress can run some internal jobs. I don’t remember exactly, but I think it runs them when someone loads the website and enough time passed since the last running or it can be executed in a cronjob I guess. But that runs on the server, not in your webbrowser so the inzternal jobs will not have access to the port that you opened on the container. When you use ā€œlocalhostā€, the localhost will mean 127.0.0.1 inside the container, nt on the host. When you use host.docker.internal, you can get DNS resolution issue, unless you add that domain to your hosts file. IT either happened in the past automatically, or you did it and your hosts file was overridden.

I would still not use host.docker.internal because that is just confusing. So I see the following options:

  • You somehow disable the features that want to access the site from the container. Wordpress community or wordpress documentation could help you
  • You use your host IP address instead of localhost. The host IP would be the same from your browser and from the container, so that should work, unless the firewall doesn’t allow you to access the host IP. And I would only do this when my host IP is a local IP, not public.
  • You add a host to your hosts file on Windows
    127.0.0.1 wordpress.local
    
    and add the same host mapping to your container:
    wordpress:
      exra_hosts:
        - "wordpress.local=127.0.0.1"
      # ...
    
    It would still not work as you also have a different port outside and inside. So you can either change the internal port if that is supported by the image, or you use port 80 on the left side of the port mapping instead of 8080. But that alone would solve your problem without a custom domain

@rimelek Thanks a lot for the reply!

I’ve done the following based on your suggestions:

Modified the compose.yml file:

services:
  db:
    image: mysql
    environment:
      MYSQL_DATABASE: wordpress_db
      MYSQL_USER: db_user
      MYSQL_PASSWORD: db_user_pass
      MYSQL_ROOT_PASSWORD: securepassword
    volumes:
      - db:/var/lib/mysql

  wordpress:
    image: wordpress:6.9.0-php8.5-apache
    ports:
     - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: wordpress_db
      WORDPRESS_DB_USER: db_user
      WORDPRESS_DB_PASSWORD: db_user_pass
    volumes:
     - wordpress:/var/www/html
    extra_hosts:
      - "wordpress.local=127.0.0.1"

volumes:
  wordpress:
  db:

And added the following to the hosts file:

127.0.0.1 wordpress.local

However, it didn’t resolve the errors from my first post.

If I try to load website using the wordpress.local address, I am getting ā€œunable to connectā€ page:

But if I add :8080 to the new address like this: http://wordpress.local:8080, I get redirected to the initial http://localhost:8080/ address, and basically, nothing changes.

Could you please explain what you meant by:

It would still not work as you also have a different port outside and inside. So you can either change the internal port if that is supported by the image, or you use port 80 on the left side of the port mapping instead of 8080. But that alone would solve your problem without a custom domain

I tried modifying the config file like this (if I understood your suggestion correctly):

  wordpress:
    image: wordpress:6.9.0-php8.5-apache
    ports:
     - 80:80

But the website stops loading after I rebuild the container with all the changes.

That’s how I rebuild it, by the way (my cmd commands):

docker-compose -f compose.yml down

docker-compose -f compose.yml up -d

I’ve seen many people experiencing similar issues as I described in my first post, but no solution has ever been explained on the internet :smiling_face_with_tear:

Yes, because

The left side of the port mapping is the port on the host .The right side is the por tin the container. The left side is available only when you try an IP that belongs to the host and not the loopback (localhost, 127.0.0.1), since that is different in every container and on the host. ā€œloop backā€ = ā€œpoint back to meā€ and there is no port 8080 inside the container.

The reason is probably the same as you had before. At least I think you mentioned somewhere you had to manually change the URL back in the database. It wouldn’t redirect you to localhost if it is not set to do it. But it is something for a Wordpress user.

That deletes containers, but not volumes, so the database will be the same as before. If anything is stored there, it will remain there.

If you want to reset all data:

docker compose down -v

Notice that I use ā€œdocker composeā€, not ā€œdocker-composeā€ which was the old way and currently it is an alias. If not, then you are using a wrong compose version. So the new way is always better.
I also removed the reference to the compose file, because it is automatically recognized.

@rimelek Thanks for the reply again!

But I still don’t understand how to fix all the errors that I am getting on the WP dashboard.

Maybe I missed something that you wrote before? :smiling_face_with_tear:

Update:

I have found a similar topic on this forum with an identical problem and described solution. I tried to implement all the steps from there, but nothing worked again…