skip to Main Content

I run WordPress with Docker Compose below and I expected WordPress to connect to and depend on my PHP container and Apache container, and actually the WordPress container uses the PHP that is in its image.

version: '3'
services:
  apache:
    image: httpd:2.4
    container_name: apache
    ports:
      - "8080:80"
    volumes:
      - ./html:/usr/local/apache2/htdocs
      #- ./config/apache/httpd.conf:/usr/local/apache2/conf/httpd.conf
      - myapp:/usr/lib/apache2/modules/
    networks:
      - mynetwork

  php:
    image: php:8.1-apache
    container_name: php
    volumes:
      - ./html:/var/www/html
      #- ./config/php:/usr/local/etc/php
      - myapp:/usr/lib/apache2/modules/
    networks:
      - mynetwork
  wordpress:
    image: wordpress:latest            
    ports:
      - "80:80"  # Change the port if 80 is already in use
    environment:
      WORDPRESS_DB_HOST: percona-mysql
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: Passw0rd
      WORDPRESS_DB_NAME: sys 
      WORDPRESS_CONFIG_EXTRA: |
        define('WP_HOME', 'http://192.168.100.15');
        define('WP_SITEURL', 'http://192.168.100.15');
        define('WP_PHP_CONTAINER', 'php');  # Adjust to your PHP container's name
        define('WP_APACHE_CONTAINER', 'apache');  # Adjust to your Apache container's name
    volumes:
      - ./wordpress:/var/www/html 
    depends_on:
      - php
    networks:
      - mynetwork

networks:
  mynetwork:
    external: true

volumes:
   myapp:

I from, I am … of

WORDPRESS_CONFIG_EXTRA: |
         define('WP_HOME', 'http://192.168.100.15');
         define('WP_SITEURL', 'http://192.168.100.15');
         define('WP_PHP_CONTAINER', php'); # Adjust to your PHP container's name

I used these things, but unfortunately, it does not connect to my internal container, and even when I stop my PHP, the Word Press container still works correctly.

2

Answers


  1. Could you explain the idea of what you’d like to achieve? Use another PHP version than in wordpress:latest image? What does mean that WordPress should connect anywhere (besides it’s db)?

    Unless you use some fancy plugins, there are no such config consts like WP_PHP_CONTAINER and WP_APACHE_CONTAINER.

    I don’t know what directories you mount to containers contain, but if you mount a WP installation folder to any container having apache or nginx configuret, it will run it.

    Login or Signup to reply.
  2. @Amir Ali … 2 problems you face here…

    1. First problem… is you are running official WordPress image as well as running PHP and Apache images. Official WordPress image is ready to go, you don’t need PHP and Apache images. Everything you need is all inclusive of Official WordPress Docker Image. Apart from your database man… please continue for this…
    2. Second major problem… is that you have no database! You need to run a database if you want to run a WP install. Classic WP databases run on mysql, but these days… it is better to run on forked mysql image known as MariaDB.

    Basic as you get docker-compose.yml approach to deploy wp locally in docker desktop with .yml is this config…

    version: '3.8'
    
    services:
    
      # here is our mariadb container
      # https://hub.docker.com/_/mariadb
      db:
        #image: mysql:5.7
        image: mariadb:11.0.2
        restart: always
        ports:
          - "3306:3306"
        environment:
          MYSQL_ROOT_PASSWORD: root
          MYSQL_DATABASE: wordpress
          MYSQL_USER: wordpress
          MYSQL_PASSWORD: wordpress
    
      # here is our wordpress container
      # https://hub.docker.com/_/wordpress
      wordpress:
        image: wordpress:latest
        restart: always
        ports:
          - "80:80"
        depends_on:
          - db
        environment:
    
          # our docker wp config settings
          WORDPRESS_DB_HOST: db:3306
          WORDPRESS_DB_USER: wordpress
          WORDPRESS_DB_PASSWORD: wordpress
          WORDPRESS_DB_NAME: wordpress
    
          # our docker wp config extra php defines
          WORDPRESS_CONFIG_EXTRA: |
    
            /** disable wp core auto update */
            define('WP_AUTO_UPDATE_CORE', false);
    

    Check out this repo link below for more advanced docker wp deployments using persistent mapping etc…

    https://github.com/joshmoto/docker-wordpress-meetup-demo/tree/main

    Hope this helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search