I'm trying to use the WordPress local development environment, which sets up a bunch of docker containers (and I'm new to Docker). One of them is a WordPress CLI, which I presume is running some scripts to do some configuration, but that particular container doesn't stay running (I believe this is intentional). I'm guessing that a script it's running is failing, and that's happening because of some configuration error, but I can't figure out how to tell what it's doing when it executes (what scripts it's running, what environment variables are set, etc...).
Is there any way to somehow "trace" what the container is trying to do?
$docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpressdevelop/phpunit latest 8ebb6f73d762 2 days ago 732MB
wordpress latest 6c2c086d9173 2 days ago 554MB
wordpress <none> 408627ce79b1 2 days ago 551MB
composer latest ff854871a595 9 days ago 173MB
wordpress cli ee6de7f71aa0 9 days ago 137MB // I want to see what this does
mariadb latest e27cf5bc24fe 12 days ago 401MB
$docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19007b991e08 wordpress "docker-entrypoint.s…" 48 minutes ago Up 48 minutes 0.0.0.0:8888->80/tcp e6bc9159b910bda3d9b0dae2e230eabd_wordpress_1
26ac5c7ec782 wordpress "docker-entrypoint.s…" 48 minutes ago Up 48 minutes 0.0.0.0:8889->80/tcp e6bc9159b910bda3d9b0dae2e230eabd_tests-wordpress_1
8ae0a4dc4f77 mariadb "docker-entrypoint.s…" 48 minutes ago Up 48 minutes 0.0.0.0:54989->3306/tcp e6bc9159b910bda3d9b0dae2e230eabd_mysql_1
This is on MacOS 11.2.2 running Docker Desktop, Docker version 20.10.5.
I'm not sure if it's relevant, but for completeness' sake, I've included the docker-compose.yml which wp-env generates, below.
Thanks!
Background
This used to Just Work, but I think I broke something in my environment, and am trying to diagnose that. I initially asked about that on WordPress StackExchange, but have since dug deeper. The Docker compose step fails thusly:
... ⠏ Configuring WordPress.Creating e6bc9159b910bda3d9b0dae2e230eabd_cli_run ... done ⠹ Configuring WordPress.mysqlcheck: Got error: 1045: Access denied for user 'username_here'@'172.19.0.5' (using password: YES) when trying to connect
The database container is left up and running, and if I go look in the database, I see it's configured to have root connect with no password:
MariaDB [(none)]> select user, host, password from mysql.user;
+-------------+-----------+----------+
| User | Host | Password |
+-------------+-----------+----------+
| mariadb.sys | localhost | |
| root | localhost | |
| root | % | |
+-------------+-----------+----------+
3 rows in set (0.003 sec)
In the main WordPress container, the wp-config.php file contains this little snippet:
...
// a helper function to lookup "env_FILE", "env", then fallback
function getenv_docker($env, $default) {
if ($fileEnv = getenv($env . '_FILE')) {
return file_get_contents($fileEnv);
}
else if ($val = getenv($env)) {
return $val;
}
else {
return $default;
}
}
...
/** MySQL database username */
define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', 'username_here') );
/** MySQL database password */
define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', 'password_here') )
Given the error message, I assume the CLI container is trying to do something similar, but the environment variables WORDPRESS_*
aren't set, and so it's using the defaults, which ... aren't working. What I think I need to do is track down something that's failing to set those variables earlier in the run process.
docker-compose.yml
version: '3.7'
services:
mysql:
image: mariadb
ports:
- '3306'
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'mysql:/var/lib/mysql'
wordpress:
build: .
depends_on:
- mysql
image: wordpress
ports:
- '${WP_ENV_PORT:-8888}:80'
environment:
WORDPRESS_DB_NAME: wordpress
volumes: &ref_0
- 'wordpress:/var/www/html'
- '/Users/cwr/src/cwra/foo:/var/www/html/wp-content/plugins/foo'
tests-wordpress:
depends_on:
- mysql
image: wordpress
ports:
- '${WP_ENV_TESTS_PORT:-8889}:80'
environment:
WORDPRESS_DB_NAME: tests-wordpress
volumes: &ref_1
- 'tests-wordpress:/var/www/html'
- '/Users/cwr/src/cwra/foo:/var/www/html/wp-content/plugins/foo'
cli:
depends_on:
- wordpress
image: 'wordpress:cli'
volumes: *ref_0
user: '33:33'
tests-cli:
depends_on:
- tests-wordpress
image: 'wordpress:cli'
volumes: *ref_1
user: '33:33'
composer:
image: composer
volumes:
- '/Users/cwr/src/cwra/foo:/app'
phpunit:
image: 'wordpressdevelop/phpunit:latest'
depends_on:
- tests-wordpress
volumes:
- 'tests-wordpress:/var/www/html'
- '/Users/cwr/src/cwra/foo:/var/www/html/wp-content/plugins/foo'
- 'phpunit-uploads:/var/www/html/wp-content/uploads'
environment:
LOCAL_DIR: html
WP_PHPUNIT__TESTS_CONFIG: /var/www/html/phpunit-wp-config.php
volumes:
wordpress: {}
tests-wordpress: {}
mysql: {}
phpunit-uploads: {}