Troubles making Nextcloud docker coexist with website

Hi, I had a Nextcloud installation coexisting peacefully on a subdomain with the main website, and wanted to move to a new server. As part of the server move I wanted to containerize Nextcloud and chose to try the official Nextcloud Docker image. However I chose to try following the guide at https://blog.ssdnodes.com/blog/installing-nextcloud-docker/ because it seemed like an alright step-by-step guide (I honestly found the official documentation to assume one knew quite a bit about both Docker and Nextcloud). However, since I already run an Nginx server on the host, I got
`ERROR: for nextcloud-proxy Cannot start service proxy: driver failed programming external connectivity on endpoint nextcloud-proxy (10266df6521e1510a8745c8c3facc68d8358cfd6034b2c8344723a679ad70a1c): Error starting userland proxy: listen tcp 0.0.0.0:443: bind: address already in use

ERROR: for proxy Cannot start service proxy: driver failed programming external connectivity on endpoint nextcloud-proxy (10266df6521e1510a8745c8c3facc68d8358cfd6034b2c8344723a679ad70a1c): Error starting userland proxy: listen tcp 0.0.0.0:443: bind: address already in use`

I only want the subdomain cloud.mydomain to direct traffic at Nextcloud, and the main site mydomain to well, go to the main site. Since the ports are already in use by Nginx serving the main site, I figured I should change the ports in the nextcloud-proxy config. So I changed my docker-compose.yml to say
5 proxy:
6 image: jwilder/nginx-proxy:alpine
7 labels:
8 - “com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true”
9 container_name: nextcloud-proxy
10 networks:
11 - nextcloud_network
12 ports:
13 - 8080:80
14 - 65432:443

It made the Docker containers spin up successfully, however it still doesn’t work and I’m honestly lost. If you’ve read this far, thanks.

one way to solve your problem: you have to migrate this server also into a container and add a VIRTUAL_HOST=example.domain.org it.

see: http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/

Okay, that could be done if I knew what I was doing. The article you linked to is soon to be six years old and requires me to download something from Github and run as root…

And now it just hangs at
2019/12/17 23:04:37 Generated ‘/etc/nginx/sites-enabled/default’ from 3 containers
2019/12/17 23:04:37 Running ‘/etc/init.d/nginx reload’
2019/12/17 23:04:37 Error running notify command: /etc/init.d/nginx reload, exit status 1
2019/12/17 23:04:37 Watching docker events
2019/12/17 23:04:37 Contents of /etc/nginx/sites-enabled/default did not change. Skipping notification ‘/etc/init.d/nginx reload’

your “main website” is just nginx with some static content?

in that case you start with putting another nginx container in your docker-compose file:

web:
  container_name: nginx_www
  image: nginx
  volumes:
      - ./www/conf.d:/etc/nginx/conf.d:ro
      - ./www/vhost.d:/etc/nginx/vhost.d:ro
      - ./www/html:/usr/share/nginx/html:ro
  environment:
    - VIRTUAL_HOST=web.YOUR-DOMAIN
    - LETSENCRYPT_HOST=web.YOUR-DOMAIN
    - LETSENCRYPT_EMAIL=YOUR-EMAIL
  networks:
    - nginx_network
  restart: unless-stopped

plus: you have to attach the proxy container as well to the nginx-network by adding this line to it’s config.

  proxy:
    image: jwilder/nginx-proxy:alpine
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
    container_name: nextcloud-proxy
    networks:
      - nextcloud_network
      - nginx_network
    ports:
      - 80:80
      - 443:443
    volumes:
       .....
.
.
.
networks:
  nextcloud_network:
  nginx_network:

the html content goes into ./www/html, the nginx config goes into ./www/conf.d + ./www/vhost.d

that’s the output of what?

Thanks for the help, I’ve resorted to taking down the website portion because I kinda need the Nextcloud server up and running.

The output I posted was from running

docker-gen -only-exposed -watch -notify "/etc/init.d/nginx reload" templates/nginx.tmpl /etc/nginx/sites-enabled/default

as per the blog post you linked to in your first post.

Anyway, I gave up using that post and just continued with the guide at https://blog.ssdnodes.com/blog/installing-nextcloud-docker/

Right now I’ve just got a question regarding files placement, it confused me a lot that it put quite a lot of files, like the config and data into a folder named ‘app’ in my home folder… in retrospect it’s obvious from this section:
volumes:
- nextcloud:/var/www/html
- ./app/config:/var/www/html/config
- ./app/custom_apps:/var/www/html/custom_apps
- ./app/data:/var/www/html/data
- ./app/themes:/var/www/html/themes
- /etc/localtime:/etc/localtime:ro

So my current inquiry is whether I should change this, and if so to what? It seems counter-intuitive to have those files there, I was sure they would be located in /var/lib/docker/volumes/[my username]_nextcloud/_data/

What would you recommend?

Oh and I also wonder how to actually change to the right database that I have backed up, the guide that I’m using says:

Wait a minute for the SSL certificate generation process to finish, and then load up the domain name you chose in your browser. Enter your chosen admin username and password. Choose MySQL as the database in the configure database section. Type in the username, password, and database name you configured via the MYSQL_USER, MYSQL_PASSWORD, and MYSQL_DATABASE environment variable from earlier. Change the hostname value from localhost to db and click Finish Setup. The system then redirects you to the Nextcloud dashboard.

However after creating username and password I got no prompt to choose database type, database username, database password nor database name, nor hostname value, so I don’t know how to proceed with restoring the MariaDB database I have.

the first line - nextcloud:/var/www/html is sufficient.
but might be a bit inconvenient.
the indention to put things in ./app is to have all content that should be in a backup in an easy to access/find place. of course you can put that as well in /var/nextcloud/data/somwhere/else. you only have to remember where you put it and/or put the correct path in your backup script. if you have one. :wink:

short version:

  • you stop nextcloud.
  • restore the database.
  • restore the datadirectory and
  • start nextcloud again.

btw: i think the howto is outdated. now - if the MYSQL_xxx variables are defined - the entrypoint.sh runs a silent system setup.

Thanks again, I’m mainly wondering how to point the Nextcloud config to the correct MariaDB database - where does the database need to reside in the filesystem, and how do I make it use it instead of the sqlite database it’s currently using? Sorry for all the silly questions, but things being in containers make me really unsure where stuff is at and where I do the config changes needed.

did you convert the database already?

https://docs.nextcloud.com/server/17/admin_manual/configuration_database/db_conversion.html

I’m trying to run

sudo docker exec --user www-data nextcloud-app php occ db:convert-type --all-apps mysql nextcloud [my_domain] nextcloud

but it times out, so it must be wrong somehow. My docker-compose db part:

4 db:
45 image: mariadb
46 container_name: nextcloud-mariadb
47 networks:
48 - nextcloud_network
49 volumes:
50 - db:/var/lib/mysql
51 - /etc/localtime:/etc/localtime:ro
52 environment:
53 - MYSQL_ROOT_PASSWORD=[redacted]
54 - MYSQL_PASSWORD= db:[redacted]
55 - MYSQL_DATABASE=nextcloud
56 - MYSQL_USER=nextcloud
57 restart: unless-stopped

My docker-compose app part:

app:
63 image: nextcloud:latest
64 container_name: nextcloud-app
65 networks:
66 - nextcloud_network
67 depends_on:
68 - letsencrypt
69 - proxy
70 - db
71 volumes:
72 - nextcloud:/var/www/html
73 - ./app/config:/var/www/html/config
74 - ./app/custom_apps:/var/www/html/custom_apps
75 - ./app/data:/var/www/html/data
76 - ./app/themes:/var/www/html/themes
77 - /etc/localtime:/etc/localtime:ro
78 environment:
79 - VIRTUAL_HOST=[redacted]
80 - LETSENCRYPT_HOST=[redacted]
81 - LETSENCRYPT_EMAIL=[redacted]
82 restart: unless-stopped

sudo docker exec --user www-data nextcloud-app php occ db:convert-type --all-apps mysql nextcloud db nextcloud
or 
sudo docker exec --user www-data nextcloud-app php occ db:convert-type --all-apps mysql nextcloud nextcloud-mariadb nextcloud

the address of the database container is db (or nextcloud-mariadb, not sure)

I always end up with

In Connection.php line 64:

Failed to connect to the database: An exception occurred in driver: SQLSTAT
E[HY000] [1045] Access denied for user ‘nextcloud’@‘172.19.0.5’ (using pass
word: YES)

I’ve tried both with and without password, with both lines, not quite sure what’s wrong or how to debug it. :thinking:

Thank you for all your patience helping me by the way, it’s highly appreciated.

you got a connection to your db container.
but you provided the wrong credentials.

it you should be this one:

Maybe I need to make a new password, I can’t make this work.

Edit: Okay I literally tried to set

54 - MYSQL_PASSWORD=test

sudo docker exec --user www-data nextcloud-app php occ db:convert-type --password “test” --all-apps mysql nextcloud nextcloud-mariadb nextcloud

In Connection.php line 64:

Failed to connect to the database: An exception occurred in driver: SQLSTAT
E[HY000] [1045] Access denied for user ‘nextcloud’@‘172.19.0.5’ (using pass
word: YES)

db:convert-type [–port PORT] [–password PASSWORD] [–clear-schema] [–all-apps] [–chunk-size CHUNK-SIZE] [–]

--password test

sudo docker exec --user www-data nextcloud-app php occ db:convert-type --password test --all-apps mysql nextcloud nextcloud-mariadb nextcloud

In Connection.php line 64:

Failed to connect to the database: An exception occurred in driver: SQLSTAT
E[HY000] [1045] Access denied for user ‘nextcloud’@‘172.19.0.5’ (using pass
word: YES)

db:convert-type [–port PORT] [–password PASSWORD] [–clear-schema] [–all-apps] [–chunk-size CHUNK-SIZE] [–]

you may try

docker exec -it nextcloud-mariadb mysql -u nextcloud nextcloud

to connect to the db.

sudo docker exec -it nextcloud-mariadb mysql -u nextcloud nextcloud
ERROR 1045 (28000): Access denied for user ‘nextcloud’@‘localhost’ (using password: NO)

sudo docker exec -it nextcloud-mariadb mysql -u nextcloud -ptest nextcloud
ERROR 1045 (28000): Access denied for user ‘nextcloud’@‘localhost’ (using password: YES)

and as user root?

That works, what would you suggest I do in the MariaDB prompt?