Nextcloud on Docker

Nextcloud is a self hosted cloud storage platform which is totally open source. Nextcloud is in use by German federal government at ITZBund( German Federal Information Technology Center ), ITZBund is the main IT services provider to the German government and provides IT services to over a million users. NextCloud claims to be GDPR compliant, so any data we host on it should be secure. The cloud storage platform has an extensive plugin library and native apps for all major mobile device operating systems. We want to install Nextcloud in a container, for this we are going to use a Docker container on Atomic Fedora, if we want to replicate our work again at the later date building containers with some sort of config is the best choice, there are many options to accomplish this task but for this example i will use docker-compose. first thing we need to do is create the directory and files


mkdir /srv/cloud

Then change into the directory


cd /srv/cloud

we want to build a docker-compose config file, we are going to use variable substitution, if we open a new file in nano :


nano docker-compose.yml

version: '2'

volumes:
  nextcloud:
  db:
    
services:
  db:
    image: mariadb
    restart: always
    volumes:
      - db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  app:
    build: .
    ports:
      - 8084:80
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
    environment:
      - NEXTCLOUD_ADMIN_USER=${NEXTCLOUD_ADMIN_USER}     
      -	NEXTCLOUD_ADMIN_PASSWORD=${NEXTCLOUD_ADMIN_PASSWORD}
      -	MYSQL_DATABASE=nextcloud
      -	MYSQL_USER=nextcloud
      -	MYSQL_PASSWORD=${MYSQL_PASSWORD}
      -	MYSQL_HOST=db:3306
    restart: always


Also create a .env file in the same directory with the values for the environment variable substitution :


nano .env

NEXTCLOUD_ADMIN_USER=example-user
NEXTCLOUD_ADMIN_PASSWORD=example-strong-password
MYSQL_PASSWORD=example-password
MYSQL_ROOT_PASSWORD=example-strong-password


Nextcloud also needs Imagick installing to get full functionality out of the theme settings, and smbclient to access other network shares unfortunately the default nextcloud build does not include them, so we have to create a new docker file in our project root:


nano Dockerfile

FROM nextcloud:latest

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        libmagickwand-dev \
        smbclient \
        libmagickcore-extra \
        && apt-get clean \
        && rm -rf /var/lib/apt/lists/*
RUN pecl install imagick
RUN docker-php-ext-enable imagick


Then its just a case of telling docker-compose to build the containers :


docker-compose up -d

Once that completes you should have NextCloud up and running all we should have to do is log in with the NEXTCLOUD_ADMIN_ credentials we setup in the config, you can test that it all works by navigating the to the port at our server for example http://server-ip:8084, you should be greeted with the login page, to get it to use a proper domain and SSL we could now setup our reverse proxy to forward traffic onto the port.

Add a Comment

Your email address will not be published. Required fields are marked *

account_circle