Docker Community Forums

Share and learn in the Docker community.

Run nextcloud on Docker swarm

Hello everyone !

I am trying to run nextcloud in Docker containers but I need a production deployment. So, I can’t use only docker-compose for production and I need to use Swarm.

This is my docker-compose file :

version: ‘3’

services:

proxy:
image: jwilder/nginx-proxy:alpine
labels:
- “com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true”
container_name: nextcloud-proxy
networks:
- nextcloud_net
- nginx_net
ports:
- 80:80
- 443:443
volumes:
- ./proxy/conf.d:/etc/nginx/conf.d:rw
- ./proxy/vhost.d:/etc/nginx/vhost.d:rw
- ./proxy/html:/usr/share/nginx/html:rw
- ./proxy/certs:/etc/nginx/certs:ro
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/tmp/docker.sock:ro

db:
image: mariadb
container_name: nextcloud-mariadb
networks:
- nextcloud_net
volumes:
- db:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
environment:
- MYSQL_ROOT_PASSWORD=OpenSource2020!
- MYSQL_PASSWORD=LesDBavantlesputes!
- MYSQL_DATABASE=nextcloud_db
- MYSQL_USER=nextcloud_db_user

app:
image: nextcloud:latest
container_name: nextcloud-app
networks:
- nextcloud_net
depends_on:
- proxy
- db
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
links:
- db
environment:
- MYSQL_PASSWORD=mysqlpassword
- MYSQL_DATABASE=nextcloud_db
- MYSQL_USER=nextcloud_db_user
- VIRTUAL_HOST=myserver.mydomain
- LETSENCRYPT_HOST=myserver.mydomain
- LETSENCRYPT_EMAIL=mail@mydomain
- NEXTCLOUD_HOSTNAME=myserver.mydomain
- NEXTCLOUD_ADMIN_USER=admin
- NEXTCLOUD_ADMIN_PASSWORD=admin

volumes:
nextcloud:
db:

networks:
nextcloud_net:
nginx_net:

When I run it with docker-compose up, everything works well !
I delete all volumes on the disk and do docker system prune --volumes to delete all and restart from scratch.

I create a swarm with :
docker swarm init

I deploy the stack :
docker stack deploy -c docker-compose.yml stack_nextcloud

Yesterday, it worked but I reach this page when I browse my server :

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

I wanted to retry today but this time I get something else.
The command docker stack deploy ends with no errors and my 3 services are created (db, app and proxy) but only the db container is created !

[root@nextcloud ~]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
mctjv5e4ygd9 swarm_nextcloud_app replicated 0/1 nextcloud:latest
0zifst1nxco9 swarm_nextcloud_db replicated 0/1 mariadb:latest
pacietpa4egi swarm_nextcloud_proxy replicated 0/1 jwilder/nginx-proxy:alpine *:80->80/tcp, *:443->443/tcp
[root@messages ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cfadc51d4bb7 mariadb:latest “docker-entrypoint.s…” 4 minutes ago Up 3 minutes 3306/tcp swarm_nextcloud_db.1.l3mqihdpkpgj6zuv0gx40sihr

What am I doing wrong ?

Thanks