wodby / docker4wordpress

Docker-based WordPress stack
https://wodby.com/docker4wordpress
MIT License
741 stars 218 forks source link

Am I missing something related to Loopback requests inside the containers locally? #81

Closed audetcameron closed 1 year ago

audetcameron commented 1 year ago

Hi there, First off, I'm not sure if this is an issue but I wasn't sure where to turn for assistance.

Rest Cron and Loopback requests are not working locally in the stack. I couldn't find a doc related to how to get those requests to operate and wanted to know if I anyone knew off the top of their head. Thank you in advance,

Codebase

Fresh Wordpress install

Host OS

e.g. macOS Ventura

REST API Endpoint: http://mysite.docker.localhost/wp-json/wp/v2/types/post?context=edit
REST API Response: (http_request_failed) cURL error 6: Could not resolve host: mysite.docker.localhost

The loopback request to your site failed, this means features relying on them are not currently working as expected.
Error: cURL error 6: Could not resolve host: mysite.docker.localhost (http_request_failed)

Does it make a difference when using port:80 vs :8000?

ps - come say hello in the wodby discord.

Info below: .env

PROJECT_NAME=mysite
PROJECT_BASE_URL=mysite.docker.localhost

PROJECT_BASE_PREFIX=http
DB_NAME=wordpress
DB_USER=wordpress
DB_PASSWORD=wordpress
DB_ROOT_PASSWORD=password
# localhost or mariadb
DB_HOST=mariadb
DB_CHARSET=utf8mb4

WP_ENV=development
WP_HOME=${PROJECT_BASE_PREFIX}://${PROJECT_BASE_URL}
WP_SITEURL=${WP_HOME}
WP_DEBUG=true
WP_DEBUG_LOG=/var/www/html/logs/debug.log

WORDPRESS_TAG=6-4.61.4
PHP_TAG=8.0-dev-macos-4.42.4
MARIADB_TAG=10.9-3.23.1
NGINX_TAG=1.23-5.29.1

docker-compose.yml

version: "3"

services:
  mariadb:
    image: wodby/mariadb:$MARIADB_TAG
    container_name: "${PROJECT_NAME}_mariadb"
    stop_grace_period: 30s
    environment:
      MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
      MYSQL_DATABASE: $DB_NAME
      MYSQL_USER: $DB_USER
      MYSQL_PASSWORD: $DB_PASSWORD

  php:
    image: wodby/wordpress-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_php"
    environment:
      SSMTP_MAILHUB: mailhog:1025
#      SSMTP_MAILHUB: opensmtpd:25
      PHP_SENDMAIL_PATH: '"/usr/bin/dos2unix -u | /usr/sbin/ssmtp -t -f"'
      DB_HOST: $DB_HOST
      DB_USER: $DB_USER
      DB_PASSWORD: $DB_PASSWORD
      DB_NAME: $DB_NAME
      PHP_FPM_USER: wodby
      PHP_FPM_GROUP: wodby
    volumes:
    - ./:/var/www/html:cached
    extra_hosts:
     - "{PROJECT_NAME}.docker.localhost:172.18.0.1"

  crond:
   image: wodby/wordpress-php:$PHP_TAG
   container_name: "${PROJECT_NAME}_crond"
   environment:
     CRONTAB: "0 * * * * wp cron event run --due-now --path=/var/www/html/web"
   command: sudo crond -f -d 0
   volumes:
   - ./:/var/www/html:cached

  nginx:
    image: wodby/nginx:$NGINX_TAG
    container_name: "${PROJECT_NAME}_nginx"
    depends_on:
    - php
    environment:
      NGINX_STATIC_OPEN_FILE_CACHE: "off"
      NGINX_ERROR_LOG_LEVEL: debug
      NGINX_BACKEND_HOST: php
      NGINX_VHOST_PRESET: wordpress
      NGINX_SERVER_ROOT: /var/www/html/web
    volumes:
    - ./:/var/www/html:cached
    labels:
    - "traefik.http.routers.${PROJECT_NAME}_nginx.rule=Host(`${PROJECT_BASE_URL}`)"

  mailhog:
    image: mailhog/mailhog
    container_name: "${PROJECT_NAME}_mailhog"
    labels:
    - "traefik.http.services.${PROJECT_NAME}_mailhog.loadbalancer.server.port=8025"
    - "traefik.http.routers.${PROJECT_NAME}_mailhog.rule=Host(`mailhog.${PROJECT_BASE_URL}`)"

  traefik:
    image: traefik:v2.0
    container_name: "${PROJECT_NAME}_traefik"
    command: --api.insecure=true --providers.docker
    ports:
    - '80:80'
    - '8080:8080' # Dashboard
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock

note, I have also tried adding an alias in trafik

    networks:
      default:
        aliases:
          - "{PROJECT_NAME}.docker.localhost"
csandanov commented 1 year ago

Discussed and resolved on discord