WordPress 4.8 on Docker REST API not available

So, I recently installed WordPress using Docker, which is a simple file filled with empty file from the Docker docs ( https://docs.docker.com/compose/wordpress/ ).

version: '3'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 
      MYSQL_DATABASE: 
      MYSQL_USER: 
      MYSQL_PASSWORD: 

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: 
      WORDPRESS_DB_PASSWORD: 
volumes:
    db_data:

      

It works and it works. This part is ok, but when I head to http://siteurl/wp-json

I get a 404. The site is working fine, but the REST API is not available. I have another site running on WAMP and when I got to this address it popped up:

{
  "name": "localhost:8090",
  "description": "Just another WordPress site",
  "url": "http://localhost:8090/wordpress",
  "home": "http://localhost:8090/wordpress",
  "gmt_offset": "0",
  "timezone_string": "",
  "namespaces": [
    "oembed/1.0",
    "wp/v2"
  ],
  ...

      

Both sites work 4.8. How to access the REST API when working with WordPress on Docker? I usually develop locally using Docker and don't remember this being a problem.

(As a side note, I deployed the WordPress container that Bitnami posted and had no problem getting the correct answer. So this is a problem with ... the official WordPress image? Maybe a base stack for the image? I can use it, but I really would love to know what the problem is because I saw a similar problem for my fellow developers)

+3


source to share


1 answer


As it turns out, this has to do with setting up a permalink for your site. The endpoint /wp-json/wp/v2

is available when you set up your site to use permalink customization. If I use the constant reference structure /%post%/

it works. There is an alternative route for sites that use different link structures:

On sites without fairly permalinks, the route is instead added to the URL as a rest_route parameter. In the above example, the full url would be http://example.com/?rest_route=/wp/v2/posts/123



Source: https://developer.wordpress.org/rest-api/extending-the-rest-api/routes-and-endpoints/

In fact, it ?rest_route=/wp/v2/posts

always works, making it more reliable.

+9


source







All Articles