chriszarate / docker-compose-wordpress

An example Docker Compose setup for WordPress plugin or theme development.
162 stars 54 forks source link

Can't connect to project.dev Port 80 #5

Closed cstromquist closed 7 years ago

cstromquist commented 7 years ago

Hi Chris,

Great repo. But am having an issue with connecting to my project.dev link. I followed the docs and have project.dev in /etc/hosts. But when I spin up Docker, I keep getting a 503 Service Unavailable error. Would you happen to know why I get that?

I'm trying to use Guzzle to connect as a client to test my REST API, but my url doesn't appear to be working.

Here's my .env:

DOCKER_DEV_DOMAIN=project.dev
DOCKER_LOCAL_IP=172.29.32.21
PHPUNIT_TEST_DIR=my-plugin

docker-compose.yml:

version: "2"

services:
  wordpress:
    image: "chriszarate/wordpress:4.7.2"
    environment:
      PHPUNIT_TEST_DIR: "/var/www/html/wp-content/plugins/my-plugin"
      VIRTUAL_HOST: "${DOCKER_DEV_DOMAIN}"
      WORDPRESS_ACTIVATE_PLUGINS: "my-plugin" # plugin folder relative to /wp-content/plugins/
      WORDPRESS_ACTIVATE_THEME: ""   # theme folder relative to /wp-content/themes/
      WORDPRESS_SITE_TITLE: "My Plugin"
      XDEBUG_CONFIG: "remote_host=${DOCKER_LOCAL_IP} idekey=xdebug"
    depends_on:
      - "mysql"
    networks:
      - "front"
      - "back"
    volumes:
      - ".:/var/www/html/wp-content/plugins/my-plugin"
  mysql:
    image: "mariadb"
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
      MYSQL_DATABASE: "wordpress"
      MYSQL_ROOT_PASSWORD: ""
    networks:
      - "back"
  mysql_phpunit:
    image: "mariadb"
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
      MYSQL_DATABASE: "wordpress_phpunit"
      MYSQL_ROOT_PASSWORD: ""
    networks:
      - "back"
  proxy:
    image: "jwilder/nginx-proxy"
    ports:
      - "8082:80"
    networks:
      front:
        aliases:
          - "${DOCKER_DEV_DOMAIN}"
    volumes:
      - "/var/run/docker.sock:/tmp/docker.sock:ro"

networks:
  front: {}
  back: {}

Thank you, Chris

cstromquist commented 7 years ago

So I found it has to do with the default port 80 which is currently used on my machine. How could I make this work on a different port like 81?

chriszarate commented 7 years ago

You're on the right track in the docker-compose.yml that you pasted above. But WordPress is redirecting you to port 80 because it thinks the canonical URL is http://project.dev.

You can run these WP-CLI commands to update WordPress's canonical URL:

docker-compose exec wordpress wp option update home http://project.dev:8080/
docker-compose exec wordpress wp option update siteurl http://project.dev:8080/

(Where project.dev is your DOCKER_DEV_DOMAIN and 8080 is the local port defined by the ports property of the proxy section of your docker-compose.yml.)

cstromquist commented 7 years ago

Got it that worked, thanks a lot!

chriszarate commented 7 years ago

Noting here that the latest version correctly respects the WORDPRESS_SITE_URL env variable. In the example above, simply set that variable to http://project.dev:8080 when bringing up the stack. No need to run the WP-CLI commands. Note however that this must be done on initial up. Changing it later has no effect.

cstromquist commented 7 years ago

Awesome, thanks Chris!