Docker Compose example
Use Docker Compose to build your own Nextcloud private cloud space
Create nextcloud template first:
Compose Template --> Add
Template name: nextcloud
Remark: my-nextcloud

Content:
version: '3'
##Specify the format version of the Compose syntax
services:
##Define service
db_nextcloud:
##Define the name of the service
image: mariadb:10.7
##Define the image used by the db_nextcloud service
container_name: db_nextcloud
##Container name, if not set, it will be named after the project name such as: 098f6bcd4621d373cade4e832627b4f6-db_nextcloud-1
restart: always
##Automatically start the container after the docker service starts
ports:
##Define mapping port
- 3366:3306
##Map host 3366 port to container 3306 port
networks:
##Define network configuration
nextcloud_net: {}
##The container uses the nextcloud_net network
command: ["--transaction-isolation=READ-COMMITTED","--binlog-format=ROW","--innodb_read_only_compressed=off"]
##Override the default command declared by the container image (ie the CMD of the Dockerfile)
volumes:
##Define volumes for container data persistence
- db_data:/var/lib/mysql
##Map the container /var/lib/mysql directory to the db_data volume
environment:
##Define the environment variables set in the container
- MYSQL_ROOT_PASSWORD=btnextcloud
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=nextcloud
##Set container environment variables: Set required variables and password for root user, create database, user, password. This user has all permissions on the database
redis_nextcloud:
##Define the name of the service
image: redis:6.2.6
##Define the image used by the redis_nextcloud service
container_name: redis_nextcloud
##Container name, if not set, it will be named after the project name
restart: always
##Automatically start the container after the docker service starts
networks:
##Define network configuration
nextcloud_net: {}
##The container uses the nextcloud_net network
command: ["--databases", "1"]
##Override the default command for container startup
volumes:
##Define volumes for container data persistence
- redis_data:/data
##Map the container /data directory to the redis_data volume
nextcloud:
##Define the name of the service
image: nextcloud:latest
##Define the image used by the nextcloud service
container_name: nextcloud_server
##Container name, if not set, it will be named after the project name
restart: always
##Automatically start the container after the docker service starts
networks:
##Define network configuration
nextcloud_net: {}
##The container uses the nextcloud_net network
ports:
##Define mapping port
- 8001:80
##Map host 8001 port to container port 80
volumes:
##Define volumes for container data persistence
- nextcloud_data:/var/www/html
##Map the container /var/www/html directory to the nextcloud_data volume
environment:
##Define the environment variables set in the container
- MYSQL_PASSWORD=nextcloud
##Use the password of the mariadb database user
- MYSQL_DATABASE=nextcloud
##Use mariadb database name
- MYSQL_USER=nextcloud
##Use the username of the mariadb database
- MYSQL_HOST=db_nextcloud
##Use the hostname of the mariadb database server. here is the name of the mariadb service
- REDIS_HOST=redis_nextcloud
##Use the hostname of the redis database server. here is the name of the redis service
- REDIS_HOST_PORT=6379
##Use the port of redis
- NEXTCLOUD_ADMIN_USER=mynextcloud
##Set the name of the nextcloud administrator user, use this username to log in to nextcloud
- NEXTCLOUD_ADMIN_PASSWORD=mynextcloud
##Set the password of the nextcloud administrator user, use this password to log in to nextcloud
- NEXTCLOUD_TRUSTED_DOMAINS= 127.0.0.1 localhost 192.168.247.129 docker129-nextcloud.com
##Set container environment variables: configure trusted ip and domain name for nextcloud, please change it to your server ip or domain name, otherwise it will not be accessible
depends_on:
##Set the order to start the service
- db_nextcloud
- redis_nextcloud
##First start the db_nextcloud and redis_nextcloud services, and then start the nextcloud service
volumes:
##Define volumes for container data persistence
nextcloud_data:
##Create nextcloud_data volume: the configuration can be empty, if the volume does not have a specified name, it will be named after the project name, such as: 098f6bcd4621d373cade4e832627b4f6_nextcloud_data
db_data:
name: "nextcloud-mariadb-data"
##Create a configuration for the db_data volume and the volume name is: nextcloud-mariadb-data
redis_data:
##Create a redis_data volume: the configuration can be empty, if the volume does not have a name specified, it will be named after the project name
networks:
##Define network configuration, a new network will be created for the project by default, but not configured
nextcloud_net:
name: "nextcloud_net"
##Create the nextcloud_net network and specify the network name as: nextcloud_net, if the network is not specified, it will be named after the project name, such as: 098f6bcd4621d373cade4e832627b4f6_default
Download the template file directly:
https://drive.google.com/file/d/1bnVsGZUSdYda-5jmMTH-5I3fThdCYHF5/view?usp=sharing
Add Compose template complete

Add Compose project:
Compose --> Add Compose project
Compose template selection just added: nextcloud

After adding, automatically pull the image

Add Compose project complete

Can also see the container of the Compose project in the "Container" interface

Access the nextcloud of the Compose project container,
Add a website to the website interface
like:

To configure proxy access to the container:
Target URL: http://127.0.0.1:8001

Use a browser to access nextcloud: http://docker129-nextcloud.com/ Please change it to your ip/domain name
The user and password here are: mynextcloud, the first login requires two logins.

Can also directly access the nextcloud container: http://192.168.247.129:8001 Please change it to your ip/domain name. If you cannot access it, please open port 8001 on the security interface
For more information on how to use Compose commands, please check the official Docker documentation:
https://docs.docker.com/compose/compose-file
You can also refer to the nextcloud official Dockerfile to build your own nextcloud image:
https://github.com/nextcloud/docker/blob/master/24/apache/Dockerfile