-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment variables no longer work in Docker Compose #576
Comments
Perhaps you can provide a more specific (minimal) example so we can try to reproduce the issue? 🙏 |
If this is in a CI environment, the likely cause is that the WordPress container will no longer wait for MySQL to be "up" / ready before it starts the web server. |
Had the same problem. My version: '3'
services:
database:
image: mariadb
ports:
- 8079:3306
volumes:
- ./database:/var/lib/mysql
restart: always
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
wordpress:
depends_on:
- database
image: wordpress:latest
volumes:
- ./site/web/app:/var/www/html/wp-content
ports:
- 8080:80
restart: always
environment:
WORDPRESS_DB_HOST: database:3306
WORDPRESS_TABLE_PREFIX: pewp_
WORDPRESS_DEBUG: 1 But with the new get_env lines: /** MySQL database password */
define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', 'password_here') ); ...empty passwords don't work anymore because Wordpress tries to login with 'password_here'. Would it be a good idea to change to the following to allow for default login? It then wouldn't be necessary to set the user and password in the docker-compose.yml file, which keeps development configuration nice and simple. /** MySQL database username */
define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', 'root') );
/** MySQL database password */
define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', '') ); (By the way if you have a running project with a local mysql or mariadb volume which you don't want to destroy, just |
See #577: we're not likely to bring back the previous insecure default, but we do want to make sure explicitly specifying an empty password works (which I think doesn't right now; I haven't verified that). As another workaround, you can safely modify your copied That being said, I would strongly recommend creating and using a non-root user with minimal privileges for running WordPress. |
@tianon thanks for your reply! I'm able to reproduce the problem with the following minimal
Everything works fine when you run To be more specific, when I use the
But when I use the
|
@tianon 👋 I have a similar configuration to @siccovansas. DockerfileFROM wordpress:5.7.0-php7.4-apache
SHELL ["/bin/bash", "-c"]
RUN apt-get update && \
apt-get install vim -y docker-compose.ymlversion: '3.6'
services:
app:
container_name: wordpress
build: .
ports:
- 1000:80
environment:
WORDPRESS_DB_HOST: mysql
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: 123
volumes:
- ./<plugin>:/var/www/html/wp-content/plugins/<plugin>
restart: always
mysql:
container_name: mariadb
image: mariadb:10.4.11-bionic
volumes:
- ./mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} # These values are coming from a .env file
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
depends_on:
- app
restart: always
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 1080:80
depends_on:
- app
- mysql
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} Here's what's set in the container's // ** 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', 'database_name_here') );
/** 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') );
/** MySQL hostname */
define( 'DB_HOST', getenv_docker('WORDPRESS_DB_HOST', 'mysql') );
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', getenv_docker('WORDPRESS_DB_CHARSET', 'utf8') );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', getenv_docker('WORDPRESS_DB_COLLATE', '') ); |
☝️ If I use the tag: |
How long did you want for MySQL to start? With the new changes, the
That is exactly how it should currently look. Part of the change is that the environment values are no longer embedded into Allowing empty passwords again is in #577. |
You are right @yosifkit! I didn't wait long enough with the 'failing' example I gave for the database to be ready. So ignore all that :) The problem seems to be that I'm using Docker Secrets (as mentioned on https://hub.docker.com/_/wordpress/). E.g., in my You can recreate the problem using this
Create the |
wordpress/wp-config-docker.php Lines 27 to 31 in fb920c6
But it seems like there is a bug if the secret files have new lines. Using the compose file in the comment just above and adding Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'test
'@'172.18.0.3' (using password: YES) in /var/www/html/wp-includes/wp-db.php on line 1653 My three secret files were just created with |
Added fix for newlines in |
Removing the newlines from the secret files indeed fixes my problem! Thanks for troubleshooting and adding a fix! Case closed I guess :) |
@yosifkit I waited for quite a bit, here's a quick video demo. It says Wordpress_Docker_Demo.mov |
@yosifkit I also noticed that there's no tables in my database 🤔 |
@kunalnagar I guess you have another issue, but it looks like you're missing |
@siccovansas I think so too. But I've tried adding Could you possibly post your |
@yosifkit @siccovansas I left it running for about 15 mins or so and it worked! 🎉 |
Same problem here #578 but without any new lines or line breaks in secrets |
Do not put |
I used |
None of the overrides worked anymore in the latest docker image because overriding requires a special wp-config.php, which we now use. See docker-library/wordpress#576 The previous values that need to be preserved are now extracted to a environment file for Docker. A future commit might also include username, password and the database values, which for now stay hard-coded.
wordpress failed to read
in I have to manually add above values to the variable so that wordpress can connect to the database. basically, |
You'd have to give more information (maybe every small step needed to reproduce the problem). We have tried and are unable to replicate the problem (except for not waiting long enough for MySQL to start). You can even click the "play-with-docker" link and see that the |
@yosifkit Follow the below steps:
a bit of explanation Now, open URL you will see this symptom: The reason is You can verify this by entering php-fpm container,
the variables are correctly shown, but If you change the variables's value in |
@winkee01 in https://github.com/winkee01/docker-nginx-php-fpm/blob/1c1788fe2a77bcd91f7501874bc95988526f1165/php-fpm.conf#L71, you're not setting See https://github.com/docker-library/php/blob/f17e9741e28808a0f642dd0487af15a3b1154ed2/7.4/bullseye/fpm/Dockerfile#L248 for where we do this in the |
After pulling the latest WordPress Docker image today I end up with a default
wp-config.php
, resulting in 'Error establishing a database connection' when trying to open my WordPress website.My
wp-config.php
doesn't contain the values I specify via environment variables in mydocker-compose.yml
, which are:WORDPRESS_DB_HOST
WORDPRESS_DB_NAME_FILE
WORDPRESS_DB_USER_FILE
WORDPRESS_DB_PASSWORD_FILE
WORDPRESS_CONFIG_EXTRA
My logs show this line:
No 'wp-config.php' found in /var/www/html, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_CONFIG_EXTRA WORDPRESS_DB_HOST WORDPRESS_DB_NAME_FILE WORDPRESS_DB_PASSWORD_FILE WORDPRESS_DB_USER_FILE)
This seems related to the recent merge of Move "wp-config-docker.php" to non-beta (5.7 GA) #572. As per this comment, I entered my Docker container and removed
wp-config.php
and restarted the container. A newwp-config.php
is generated (giving the same message in my logs as shown above), but this is the same as the previous one and doesn't contain the values from my environment variables.I guess the new issues #573 and #574 are related.
I pull new WordPress docker images on a daily bases, and this problem hasn't occurred before. So I guess it is not caused on my end.
The text was updated successfully, but these errors were encountered: