You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got a running WP-container with the following wp-config.php (official source):
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', getenv_docker('WORDPRESS_DB_NAME', 'wordpress') );
/** MySQL database username */
define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', 'example username') );
/** MySQL database password */
define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', 'example password') );
Then I want to execute a basic command but that fails due to the parsing of the database credentials
docker run -it --rm \
--volumes-from wp \
--network container:wp \
wordpress:cli-php8.0 user list
Error: Error establishing a database connection.
Is there any way how I can supply the credentials?
I can already extract them from docker-compose.yml using this: db_name=$(grep -Po '(?<=WORDPRESS_DB_NAME: )(.*)' docker-compose.yml)
workaround for now is to create an additional entrypoint.sh for docker wp container and change the values in wp-config using sed. But I would rather see something native from wp-cli
NOTE: Since March 2021, WordPress images use a customized wp-config.php that pulls the values directly from the environment variables defined above (see wp-config-docker.php in docker-library/wordpress#572 and docker-library/wordpress#577). As a result of reading environment variables directly, the cli container also needs the same set of environment variables to properly evaluate wp-config.php.
Activity
Kipjr commentedon Apr 21, 2021
workaround for now is to create an additional entrypoint.sh for docker wp container and change the values in wp-config using sed. But I would rather see something native from wp-cli
ElieMyIdea commentedon May 31, 2021
Hi,
Same problem here :/
caliuf commentedon Jun 9, 2021
Try to pass to the wpcli container the same env vars you pass to the wordpress container.
e.g. WORDPRESS_DB_HOST, ecc
maurisrx commentedon Jul 31, 2021
To further elaborate @caliuf comment, here is the note from Docker WP page:
dbrosy commentedon Jul 6, 2022
is there a solution for this yet? I have built a new docker wordpress image and the env vars are there but are not being read.
Appreciate any assistance as my solution is to replace wp-config.php with old style file
Kipjr commentedon Jul 7, 2022
And with this wrapper so I can source the env from a json file:
https://raw.githubusercontent.com/VSLCatena/docker-wordpress/master/wp-cli.sh
danielbachhuber commentedon Apr 26, 2023
Feel free to stop by the
#clichannel on WordPress.org Slack if you'd like help debugging further.