Uh oh!
There was an error while loading. Please reload this page.
Inject configuration using environment variable - #142
Conversation
nithin-bose
commented
Aug 8, 2017
I really hope this PR would be merged. I don't see any point in making new images just for config changes, especially since this PR would let me do the same without any overhead or major impact. What is stopping this PR from being merged?? |
simonwh
commented
Aug 9, 2017
Great idea, why not merge it? |
l00ptr
commented
Oct 6, 2017
Yeah it could be nice to add some extra config that way. I want to force and set the https. |
ping @tianon@marsjaninzmarsa ... or, at least, allow to bind mount
|
Just rebased this branch in the hope of a timely merge, and wrapped the |
luiscoms
commented
Mar 19, 2018
Hi, I`ve tested your change, and it works but for php5.6 you need to update this file |
Right! It's just a copy though, so it was an easy thing to do 😄 I also updated the other entrypoint files. |
luiscoms
commented
Mar 23, 2018
This error raises when
To fix this you need to change to |
lwille
commented
Mar 25, 2018
d'uh! Thanks for the tipp @luiscoms 👍 |
scottbasgaard
commented
Apr 3, 2018
Looking forward to this! |
kaayru
commented
Apr 16, 2018
Nice addition! Is this going to be approved and merged soon? |
lwille
commented
Apr 16, 2018
rebased to keep this branch fresh and ready to be merged |
1gor
commented
Apr 17, 2018
Much needed feature. What prevents it from being merged? |
lwille
commented
Apr 17, 2018
@tianon Can we have a decision? I'd like to strike this off my list of open things ;-) |
acuthbert
commented
Apr 19, 2018
Need to get a setup a multisite instance using docker for internal development - really need this merged! Pretty please? |
tianon
left a comment
There was a problem hiding this comment.
Sorry for the long delay -- we've oscillated a lot on how to resolve the issue of users providing additional configuration to this image specifically because it's a bit complicated and everyone seems to have a slightly different opinion on how they'd like that to work.
I think this PR provides the best compromise, so I'd like to move forward on it. 👍
| if [ ! -e wp-config.php ]; then | ||
| awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' wp-config-sample.php > wp-config.php <<'EOPHP' | ||
| awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' wp-config-sample.php > wp-config.php <<'EOPHP' <<EOBASH |
There was a problem hiding this comment.
This multi-heredoc syntax seemed too good to be true, so I tested and it does appear to be too good to be true: 😞
$ cat <<EOF1 <<EOF2
> hi
> EOF1
> hi2u
> EOF2hi2uIt appears the second overwrites the first. However, all three implementations of awk that I tested (busybox, mawk, and gawk) include an ENVIRON variable which we can use. Here's my suggested modification:
awk ' /^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1 system("cat") if (ENVIRON["WORDPRESS_ADDITIONAL_CONFIG"]) { print ENVIRON["WORDPRESS_ADDITIONAL_CONFIG"] } } { print }' wp-config-sample.php > wp-config.php <<'EOPHP'...EOPHPThere was a problem hiding this comment.
Strange, the actual implementation works for me
There was a problem hiding this comment.
Im using different heredoc styles, maybe that’s why 🤔
proof: squashed my commits. edit: my proof is only working in |
cvrabie
commented
Jun 5, 2018
Any update? Seems multiple feature requests have been closed in favour of this then it all went quiet. |
I am using the following to autodetect whether the wordpress site url has changed and automatically modify it in the Dockerfile: I had to copy the |
lbod
commented
Jul 24, 2018
Rather than writing a configurable option to pass in any number of wordpress env variables (even though it makes more sense), does it not make sense to just hardcode the It seems daft I can only use a bare minimum of env variables, otherwise I'm faced with creating my own image and entrypoint which takes away the reason for using this image in the first place, ease of use. |
ConstantinElse
commented
Jul 24, 2018
When this PR is going to be merged ? |
tstricklin-digital
commented
Jul 24, 2018
This could work for a wide range of needs, but it's not a proper full solution unless you hard-code 100% of all possible environment variables. And as WP introduces new variables, this would need to be kept up-to-date. Personally, I'm all for the solution proposed in this PR. |
reidab
commented
Nov 27, 2018
Since the README on the Docker hub page links to this issue for more context, it would be nice to edit the top-level description here to reference the final name, |
morenoh149
commented
Nov 27, 2018
@reidab it's been updated by @wglambert |
This comment has been minimized.
This comment has been minimized.
jakobojvind
commented
Dec 25, 2018
I had a similar problem with To reproduce my problem (an, update docker-compose.yml scenario)
Now the My solution was
Now the |
tianon
commented
Jan 15, 2019
For cases where this doesn't seem to be taking effect, if you check your container logs you'll likely see the warning that was added in #342. 👍 The solutions are either to not mount a previous install (let the script provide the initial If you'd like a solution that will update dynamically from an environment variable, see the |
SloCompTech
commented
Feb 6, 2019
If anyone gets an database error when trying to configure multisite with: WORDPRESS_CONFIG_EXTRA: | /* Multisite */ define('WP_ALLOW_MULTISITE', true ); define('MULTISITE', true); define('SUBDOMAIN_INSTALL', false); define('DOMAIN_CURRENT_SITE', 'localhost'); // TODO: change to actual domain when deploying define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1);use this instead WORDPRESS_CONFIG_EXTRA: | /* Multisite */ define('WP_ALLOW_MULTISITE', true );then manualy go via Tools -> Network setup If anyone interested in stacktrace: |
r4ym0n
commented
Mar 29, 2019
HI, all. here got bug about this feature , If I set the cofig. below. the IN SO, when I access the website, It will redirect to array/path/to/wp |
tianon
commented
Mar 29, 2019
@quartz010 you've got something else swallowing your For further help, please try the Docker Community Forums, the Docker Community Slack, or Stack Overflow (these issues are not a support forum and this feature is confirmed to be working properly for other users). |
luiscoms
commented
Apr 1, 2019
You can scape |
r4ym0n
commented
Apr 1, 2019
☆⌒(*^-゜)v THX!! Solved! |
I get database error "Error establishing a database connection" |
What am I missing here? When trying to setup a multisite docker wordpress instance I get the following error after hitting http://localhost:8080
docker-compose.yaml version: '3.7'
services:
wordpress-cli:
image: wordpress:cli
container_name: wordpress-cli
depends_on:
- wordpress
volumes:
- wordpress:/var/www/html
wordpress:
image: wordpress
container_name: wordpress
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST:-db:3306}
WORDPRESS_DB_USER: ${WORDPRESS_DB_USER:-wp_admin}
WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
WORDPRESS_CONFIG_EXTRA: |
/* Multisite */
define('WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'localhost'); define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
depends_on:
- db
volumes:
- wordpress:/var/www/html
db:
image: mysql:8.0.18
container_name: db
command: --default-authentication-plugin=mysql_native_password
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: ${WORDPRESS_DB_USER:-wp_admin}
MYSQL_PASSWORD: ${WORDPRESS_DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- wordpress-db:/var/lib/mysql
- ./data/mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
volumes:
wordpress-db:
name: wordpress-db
wordpress:
name: wordpress.env WORDPRESS_DB_PASSWORD=whatever-you-want
MYSQL_ROOT_PASSWORD=whatever-root-pwd-you-wantWhy is it trying to access the db before going through the setup process? mysql> use wordpress;
Database changed
mysql> show tables;
Empty set (0.01 sec)If I remove the @lwille, any ideas? |
jamg44
commented
Mar 24, 2020
@spencerdcarlson I had the same issue, and used successfully the workarround proposed above by @SloCompTech |
oaklsb
commented
Aug 25, 2020
Hey, is there a solution now outside of the workaround mentioned above? Such that all config could be done in the compose file? Thanks in advance |


Alternative solution to #8. Not passing in
WORDPRESS_CONFIG_EXTRAwon't break anything.Here's an excerpt from my multisite docker-compose.yaml with
WORDPRESS_CONFIG_EXTRA:The generated wp-config.php looks like this (excerpt):