简体   繁体   中英

Docker Local Wordpress Development

I have followed the Wordpress quick start tutorial to get my local dev environment setup. However, I am trying to setup my local environment to use local.mysite.com instead of the default localhost http://localhost:8080. I've added local.mysite.com to my hosts file and updated all of the urls in the database to point towards local.mysite.com. But I can not access the site in my browser.

I've searched for a while, but the only solutions I found say that I need to add a reverse proxy to the docker-compose ( https://objectpartners.com/2020/09/01/local-wordpress-development-with-docker/ ), but they don't explain why that is required. My understanding is that port 80 is bound to my wp image and as such http requests should be routed directly to it.

Looking to understand either how to properly set this up to use a custom url without a reverse proxy, or to get a much better understanding as to why one is required.

services:
  wp:
    image: wordpress:latest 
    ports:
      - 80:80 
    volumes:
      #- ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
      - ./wp-app:/var/www/html # Full wordpress project
      - ./wp-content/:/var/www/html/wp-content
    environment:
      DB_HOST: db
      DB_NAME: "*****"
      DB_USER: "*****"
      DB_PASSWORD: "*****"
    depends_on:
      - db

The reverse proxy is only needed if you publish the container on another port than 80.

If the ports section in the docker-compose.yml below would show "8080:80", then it is not possible to map a domainname to the container since domainnames cannot point to ports, only to IP-addresses.

But you already publish on port 80 on the host, so a reverse proxy does not seem to be necessary.

Can't see what is wrong with your environment. Only way I can help you is to show a working Wordpress Docker env.

docker-compose.yml

version: '3.9'

services:

  db:
    image: mysql:5.7
    container_name: mysql
    volumes:
      - ./database:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: word@press
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: abc@123

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    container_name: wp
    volumes:
      - ./wordpress_files:/var/www/html
    ports:
      - "80:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: abc@123

The docker-compose creates 2 containers:

  • mysql: The container running the MySQL database
  • wp: The container running Wordpress

Directories

Create 2 directories on the same level as docker-compose.yml:

  • database
  • wordpress_files

Create the domainname

In your /etc/hosts (Mac an Linux. Don't know about Windows) create the following line:

127.0.0.1   local.mysite.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM