What Is Nextcloud?
What Is Nextcloud?
What Is Nextcloud?
Now you can access Nextcloud at http://localhost:8080/ from your host system.
As the fastCGI-Process is not capable of serving static files (style sheets, images, ...) the webserver
needs access to these files. This can be achieved with the volumes-from option. You can find
more information in the docker-compose section.
Using an external database
By default this container uses SQLite for data storage, but the Nextcloud setup wizard (appears on
first run) allows connecting to an existing MySQL/MariaDB or PostgreSQL database. You can also
link a database container, e. g. --link my-mysql:mysql, and then use mysql as the database
host on setup. More info is in the docker-compose section.
Persistent data
The Nextcloud installation and all data beyond what lives in the database (file uploads, etc) is stored
in the unnamed docker volume volume /var/www/html. The docker daemon will store that data
within the docker directory /var/lib/docker/volumes/.... That means your data is saved
even if the container crashes, is stopped or deleted.
To make your data persistent to upgrading and get access for backups is using named docker
volume or mount a host folder. To achieve this you need one volume for your database container
and Nextcloud.
Nextcloud:
/var/www/html/ folder where all nextcloud data lives
$ docker run -d nextcloud \
-v nextcloud:/var/www/html
Database:
/var/lib/mysql MySQL / MariaDB Data
/var/lib/postresql/data PostegreSQL Data
$ docker run -d mariadb \
-v db:/var/lib/mysql
If you want to get fine grained access to your individual files, you can mount additional volumes for
data, config, your theme and custom apps. The data, config are stored in respective subfolders
inside /var/www/html/. The apps are split into core apps (which are shipped with Nextcloud
and you don't need to take care of) and a custom_apps folder. If you use a custom theme it
would go into the themes subfolder.
If you want to use named volumes for all of these it would look like this
$ docker run -d nextcloud \
-v nextcloud:/var/www/html \
-v apps:/var/www/html/custom_apps \
-v config:/var/www/html/config \
-v data:/var/www/html/data \
-v theme:/var/www/html/themes/<YOUR_CUSTOM_THEME>
or for docker-compose:
$ docker-compose exec --user www-data app php occ
MYSQL/MariaDB:
MYSQL_DATABASE Name of the database using mysql / mariadb.
MYSQL_USER Username for the database using mysql / mariadb.
MYSQL_PASSWORD Password for the database user using mysql / mariadb.
MYSQL_HOST Hostname of the database server using mysql / mariadb.
PostgreSQL:
POSTGRES_DB Name of the database using postgres.
POSTGRES_USER Username for the database using postgres.
POSTGRES_PASSWORD Password for the database user using postgres.
POSTGRES_HOST Hostname of the database server using postgres.
If you set any values, they will not be asked in the install page on first run. With a complete
configuration by using all variables for your database type, you can additionally configure your
Nextcloud instance by setting admin user and password (only works if you set both):
NEXTCLOUD_ADMIN_USER Name of the Nextcloud admin user.
NEXTCLOUD_ADMIN_PASSWORD Password for the Nextcloud admin user.
If you want you can set the data directory and table prefix, otherwise default values will be used.
NEXTCLOUD_DATA_DIR (default: /var/www/html/data) Configures the data directory
where nextcloud stores all files from the users.
NEXTCLOUD_TABLE_PREFIX (default: "") Optional prefix for the tables. Used to be oc_
in the past
volumes:
nextcloud:
db:
services:
db:
image: mariadb
restart: always
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_PASSWORD=
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app:
image: nextcloud
ports:
- 8080:80
links:
- db
volumes:
- nextcloud:/var/www/html
restart: always
Then run docker-compose up -d, now you can access Nextcloud at http://localhost:8080/
from your host system.
Base version - FPM
When using the FPM image you need another container that acts as web server on port 80 and
proxies the requests to the Nextcloud container. In this example a simple nginx container is
combined with the Nextcloud-fpm image and a MariaDB database container. The data is stored in
docker volumes. The nginx container also need access to static files from your Nextcloud
installation. It gets access to all the volumes mounted to Nextcloud via the volumes_from
option.The configuration for nginx is stored in the configuration file nginx.conf, that is
mounted into the container. An example can be found in the examples section here.
As this setup does not include encryption it should to be run behind a proxy.
Make sure to set the variables MYSQL_ROOT_PASSWORD and MYSQL_PASSWORD before you run
this setup.
version: '2'
volumes:
nextcloud:
db:
services:
db:
image: mariadb
restart: always
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_PASSWORD=
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app:
image: nextcloud:fpm
links:
- db
volumes:
- nextcloud:/var/www/html
restart: always
web:
image: nginx
ports:
- 8080:80
links:
- app
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
volumes_from:
- app
restart: always
Then run docker-compose up -d, now you can access Nextcloud at http://localhost:8080/
from your host system.
Make your Nextcloud available from the
internet
Until here your Nextcloud is just available from you docker host. If you want you Nextcloud
available from the internet adding SSL encryption is mandatory.
First use
When you first access your Nextcloud, the setup wizard will appear and ask you to choose an
administrator account, password and the database connection. For the database use db as host and
nextcloud as table and user name. Also enter the password you chose in your docker-
compose.yml file.
Beware that you have to run the same command with the options that you used to initially start your
Nextcloud. That includes volumes, port mapping.
When using docker-compose your compose file takes care of your configuration, so you just have to
run:
$ docker-compose pull
$ docker-compose up -d
Adding Features
A lot of people want to use additional functionality inside their Nextcloud installation. If the image
does not include the packages you need, you can easily build your own image on top of it. Start
your derived image with the FROM statement and add whatever you like.
FROM nextcloud:apache
RUN ...
The examples folder gives a few examples on how to add certain functionalities, like including the
cron job, smb-support or imap-authentication.
If you use your own Dockerfile you need to configure your docker-compose file accordingly.
Switch out the image option with build. You have to specify the path to your Dockerfile. (in the
example it's in the same directory next to the docker-compose file)
app:
build: .
links:
- db
volumes:
- data:/var/www/html/data
- config:/var/www/html/config
- apps:/var/www/html/apps
restart: always
Updating your own derived image is also very simple. When a new version of the Nextcloud image
is available run:
docker build -t your-name --pull .
docker run -d your-name
or for docker-compose:
docker-compose build --pull
docker-compose up -d
The --pull option tells docker to look for new versions of the base image. Then the build
instructions inside your Dockerfile are run on top of the new image.
2. Make sure you have no configuration for the apps_paths. Delete lines like these
- "apps_paths" => array (
- 0 => array (
- "path" => OC::$SERVERROOT."/apps",
- "url" => "/apps",
- "writable" => true,
- ),
5. Copy only the custom apps you use (or simply redownload them from the web interface):
docker cp ./apps/ nextcloud_data:/var/www/html/custom_apps
docker-compose exec app chown www-data:www-data /var/www/html/custom_apps