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
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.
@Amir Ali … 2 problems you face here…
Basic as you get docker-compose.yml approach to deploy wp locally in docker desktop with
.yml
is this config…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!