-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 ignored in docker-compose scenarios #1201
Comments
I believe I've found my way here from the reverse proxy problems, and the |
Running it with docker-compose still runs the entrypoint.sh file. I just had the same issue and the problem is that the way the entrypoint is written is an "all or nothing at all" approach. To set the DB, you need to specify the 4 variables (MYSQL_HOST, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD). But even if you set these, you cannot set the DB or Trusted Domains if you don't define NEXTCLOUD_ADMIN_USER and NEXTCLOUD_ADMIN_PASSWORD. There is a big if clause that will skip treating the SQL and trusted domains env vars if the admin vars are not set. The documentation does not mention this. In fact, the documentation is misleading as it says that the env vars are used to prepopulate values. I was expecting to get to the start page and have the DB variables populated,even if I had not specified an admin user. |
@ptoulouse I cannot reproduce this. I struggled initially because I forgot to add the MYSQL_HOST variable, but after that, the prepopulation worked perfectly, as implied by the documentation. |
What I am saying is that the MYSQL_* and NEXTCLOUD_TRUSTED_DOMAINS are ignored if the NEXTCLOUD_ADMIN_* variables are not set. See entrypoint.sh at line 121 and down. Also the 4 MYSQL_* vars need to be set to initialize the DB. The Readme implies that the MYSQL_* vars will be populated even without NEXTCLOUD_ADMIN_* being set. |
@ptoulouse I understood. What I'm saying is that despite what the entrypoint.sh looks like, I was able to install nextcloud with mariadb following the README using docker-compose: version: '2'
services:
nextcloud:
image: nextcloud
container_name: nextcloud
restart: always
environment:
- MYSQL_HOST=nextcloud-database
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud_database_user
- MYSQL_PASSWORD=nextcloud_database_password
- VIRTUAL_HOST=nextcloud.example.com
- LETSENCRYPT_HOST=nextcloud.example.com
- LETSENCRYPT_EMAIL=admin@example.com
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /mnt/vol1/nextcloud:/var/www/html
ports:
- "8080:80"
links:
- nextcloud-database
nextcloud-database:
image: mariadb:10.3.22 # See https://github.com/nextcloud/docker/issues/1038
container_name: nextcloud-database
restart: always
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
environment:
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud_database_user
- MYSQL_PASSWORD=nextcloud_database_password
- MYSQL_ROOT_PASSWORD=nextcloud_database_root_password
volumes:
- /mnt/vol1/database:/var/lib/mysql I did try this two more times after completely wiping vol1 and it works perfectly. The database connection is initialized, I could enter a username and password in the web-interface, <?php
$CONFIG = array (
'htaccess.RewriteBase' => '/',
'memcache.local' => '\\OC\\Memcache\\APCu',
'apps_paths' =>
array (
0 =>
array (
'path' => '/var/www/html/apps',
'url' => '/apps',
'writable' => false,
),
1 =>
array (
'path' => '/var/www/html/custom_apps',
'url' => '/custom_apps',
'writable' => true,
),
),
'instanceid' => 'ocaykbzzgr4w',
'passwordsalt' => 'rt2LI5mPfLZ69i9B0WwFSefzjlOgJI',
'secret' => 'M0v1wTgTKTOcVcb1HEVJrZAAEDO/5sKWML7NmOobIgckPQJU',
'trusted_domains' =>
array (
0 => 'nextcloud.example.com',
),
'datadirectory' => '/var/www/html/data',
'dbtype' => 'mysql',
'version' => '21.0.1.1',
'overwrite.cli.url' => 'http://nextcloud.example.com',
'dbname' => 'nextcloud',
'dbhost' => 'nextcloud-database',
'dbport' => '',
'dbtableprefix' => 'oc_',
'mysql.utf8mb4' => true,
'dbuser' => 'nextcloud_database_user',
'dbpassword' => 'nextcloud_database_password',
'installed' => true,
); However, this doesn't work when using the |
This is incorrect:
The ENTRYPOINT definition in the Dockerfile specifies what a container should run as the entrypoint at start time. The entrypoint is absolutely invoked when you start a container.
Well, they're not used when you manually run the Nextcloud installer as you did in your test cases. But that's not surprising. You're overriding how this image works. :-) Those variables are injected through the entrypoint when a container starts for the first time. Those particular ones are passed to the installer within the entrypoint.
Because they do. There are multiple ways of injecting them internally. What you don't see in the entrypoint, is that the I'm going to close this for the following reasons:
|
The documentation
explicitly statesstrongly implies that environment variables can be used to configure containers when usingdocker-compose
. For example:Also some of the
docker-compose.yml
examples apparently use env vars to setMYSQL*
vars for the Nextcloud container:But this doesn't work. AFAICT, the documentation is assuming that since passing env vars works with a Dockerfile, it will also work with
docker-compose
, butdocker-compose
doesn't run thedocker-entrypoint.sh
file that gets run by a Dockerfile.The question for me is whether this is purely a documentation problem, or if this is a missing feature.
To reproduce
Reproduction script
Script
Output
The above script uses a very slightly modified version of the 'Base version - apache' sample from the README to:
php occ maintenance:install
with no admin password (this fails),php occ maintenance:install
with an admin password (this succeeds),config/config.php
.The output demonstrates that:
nextcloud
container,db
container,NEXTCLOUD_ADMIN_*
vars are not used by the installer,MYSQL_*
vars are not used by the installer.The text was updated successfully, but these errors were encountered: