简体   繁体   中英

URL issue in Docker Wordpress site

I wanted to create a local dev environment for a wordpress site using docker. So I have the following docker-compose file :

version: '3'

services:
  db:
    image: mariadb
    restart: on-failure
    environment:
    - MYSQL_DATABASE=${WP_DB_NAME}
    - MYSQL_USER=${WP_DB_USER}
    - MYSQL_PASSWORD=${WP_DB_USER_PASSWORD}
    volumes:
    #- ./db_data:/var/lib/mysql
    - ./mysql_dump/backup.sql:/docker-entrypoint-initdb.d/backup.sql
    - ./mysql_dump/migrate.sql:/docker-entrypoint-initdb.d/migrate.sql
    networks:
    - local

  wordpress:
    image: wordpress
    depends_on:
    - db
    restart: always
    ports:
      - 8080:80
    environment:
    - WORDPRESS_DB_HOST=db
    - WORDPRESS_DB_USER=${WP_DB_USER}
    - WORDPRESS_DB_PASSWORD=${WP_DB_USER_PASSWORD}
    - WORDPRESS_DB_NAME=${WP_DB_NAME}
    volumes: 
    - ./htdocs:/var/www/html
    networks:
      local:
        ipv4_address: 172.23.0.4

networks:
  local:
    driver: bridge
    ipam:
      config:
      - subnet: 172.23.0.0/24

I use volume to start mariadb with existing database dump.

Website is loading fine, but some URLs are wrong :

  • When I try to connect, I am redirected to : http://172.23.0.4/172.23.0.4/wp-admin/ for example
  • Some js scripts are also not loaded due to wrong URLs like http://172.23.0.4172.23.0.4/wp-includes/js/tinymce/tinymce.min.js?ver=4920-20181217

I checked the general settings in the admin panel, and the values siteurl and home in the database and they are correct : 172.23.0.4 . The website in production (no docker but classic LAMP install) is working fine by the way…

Do you have any hints ? (I'm not that familiar with web development, especially with wordpress)

Looks like specifying 172.23.0.4 in wordpress settings for home and siteurl is somehow (don't know why though) causing the issue. Instead, setting the value to http://172.23.0.4 fixed the problem.

If someone has some explanation, please tell me.

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