When I run the docker-compose file docker-compose/with-nginx-proxy/mariadb-cron-redis/fpm/docker-compose.yml (with letsencrypt removed), the app-container cannot connect to the mysql-instance. When I try to create an admin-user, the following error appears:
Error while trying to create admin user: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user 'nextcloud'@'172.18.0.5' (using password: YES)
docker-compose.yml:
version: '3'
services:
db:
build: ./db
restart: always
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=password
env_file:
- db.env
redis:
image: redis
restart: always
app:
build: ./app
restart: always
volumes:
- nextcloud:/var/www/html
environment:
- MYSQL_HOST=db
env_file:
- db.env
depends_on:
- db
- redis
web:
build: ./web
restart: always
volumes:
- nextcloud:/var/www/html:ro
environment:
- VIRTUAL_HOST=192.168.192.163
#- LETSENCRYPT_HOST=
#- LETSENCRYPT_EMAIL=
depends_on:
- app
networks:
- proxy-tier
- default
cron:
build: ./app
restart: always
volumes:
- nextcloud:/var/www/html
entrypoint: /cron.sh
depends_on:
- db
- redis
proxy:
build: ./proxy
restart: always
ports:
- 80:80
- 443:443
# labels:
# com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
volumes:
# - certs:/etc/nginx/certs:ro
- vhost.d:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
- proxy-tier
volumes:
db:
nextcloud:
# certs:
vhost.d:
html:
networks:
proxy-tier:
db.env:
MYSQL_PASSWORD=password
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
Does your database exist? I sometimes had the problem that the database-containers do not read from the env.-files
Try defining them directly in the environment - section.
Hi I get the same issue even with a simple example where I tried to put everywhere nextcloud even as password:
version: '3'
volumes:
nextcloud:
db:
services:
db:
image: mariadb
restart: always
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=nextcloud
- MYSQL_PASSWORD=nextcloud
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app:
image: nextcloud
ports:
- 4444:80
links:
- db
- redis
volumes:
- nextcloud:/var/www/html
restart: always
redis:
image: redis
restart: always

I suggest that the problem comes from the field where I wrote "db" ?
(I also tried localhost, 0.0.0.0, 127.0.0.1) but same issue or I get ( connection refused )
db as hostname is correct in your setup
localhost 127.0.0.1 is not correct
Do you remove your mysql-data between your tests? For in your first test you write
MYSQL_PASSWORD=password
and in your second
- MYSQL_PASSWORD=nextcloud
I recommend to remove all your data between your tests and start with a blank setup each time.
I would also try use
depends_on:
- db
and define the MYSQL-env-vars in the app-section, too.
Hi @rdxmb,
I think you didn't see that I'm not the author of this thread, I never set password as password ').
So I'm not sure if the previous answer is for me or not ')
I just wrote a basic example to show the issue which is the same as the author of this issue ')
@kevincaradant oops, you are right, I am sorry (it's late in Germany)
Nevertheless, try it with depends. And the links - section is not necessary.
@kevincaradant just tried your compose-file. Everything works well in my case.
docker-compose -v
docker-compose version 1.21.0, build 5920eb0
docker2.mbr.intern:/mnt/docker/check# docker version
Client:
Version: 17.06.1-ce
API version: 1.30
Go version: go1.8.3
Git commit: 874a737
Built: Thu Aug 17 22:51:12 2017
OS/Arch: linux/amd64
Server:
Version: 17.06.1-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: 874a737
Built: Thu Aug 17 22:50:04 2017
OS/Arch: linux/amd64
Experimental: false
Seems like you have docker volumes which contain old data (e.g. with old passwords saved...)
@rdxmb, don't worry, it's late in France too :)
I tried this:
version: '3'
volumes:
nextcloud:
db:
services:
db:
image: mariadb
restart: always
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=nextcloud
- MYSQL_PASSWORD=nextcloud
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app:
image: nextcloud
ports:
- 4444:80
volumes:
- nextcloud:/var/www/html
restart: always
depends_on:
- db
- redis
redis:
image: redis
restart: always
same issue :/. Do I miss something ?
When you said, everything works ? Did you try to create an user at yourIP:4444 ? Because it's during the process to create an user that I get the error ;)
My versions:
docker-compose version 1.18.0, build 8dd22a9
Docker version 18.03.1-ce, build 9ee9f40
@rdxmb You're right! Thank you :)
I removed all containers about nextcloud
I followed all steps here:
https://gist.github.com/bastman/5b57ddb3c11942094f8d0a97d461b430
And try in private tab in the browser: SUCCESS :)
So thank you again, I hope my issue can help the author ...
correct, removing containers does not remove the volumes.
I'll then close this issue, feel free to reopen if necessary, and thanks for your help!
I can confirm that cleaning up all volumes solved the issue! Thanks for all your help!
Most helpful comment
I can confirm that cleaning up all volumes solved the issue! Thanks for all your help!