Mounting External Hard Drives for NextCloud

Hoping to get some clarification on working with external drives. I know I am likely missing a key concept somewhere with regards to what the correct way is to do this and some of the documentation seems to contradict itself but in any case, I have a cluster of 3 RPI4s and a RPI3 on the balenaOS 2.44.0+rev3 OS. Right now I am trying to spin up a NextCloud Container and followed the guide here and added the fstab edits to my dockerfile:

FROM lsiobase/nginx:3.10

# set version label
ARG BUILD_DATE
ARG VERSION
ARG NEXTCLOUD_RELEASE
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
LABEL maintainer="sparklyballs"

# environment settings
ENV NEXTCLOUD_PATH="/config/www/nextcloud"
ENV UDEV=1


RUN echo "LABEL=storage1 /data/storage1 ext4 rw,relatime,discard,data=ordered 0 2" >> /etc/fstab && \
    echo "LABEL=storage2 /data/storage2 ext4 rw,relatime,discard,data=ordered 0 2" >> /etc/fstab

RUN rc-service localmount start

RUN \
 echo "**** install build packages ****" && \
 apk add --no-cache --virtual=build-dependencies --upgrade \
	autoconf \
	automake \
	file \
	g++ \
	gcc \
	make \
	php7-dev \
	re2c \
	samba-dev \
	zlib-dev && \
 echo "**** install runtime packages ****" && \
 apk add --no-cache --upgrade \
	curl \
	ffmpeg \
	imagemagick \
	libxml2 \
	php7-apcu \
	php7-bz2 \
	php7-ctype \
	php7-curl \
	php7-dom \
	php7-exif \
	php7-ftp \
	php7-gd \
	php7-gmp \
	php7-iconv \
	php7-imagick \
	php7-imap \
	php7-intl \
	php7-ldap \
	php7-mcrypt \
	php7-memcached \
	php7-opcache \
	php7-pcntl \
	php7-pdo_mysql \
	php7-pdo_pgsql \
	php7-pdo_sqlite \
	php7-pgsql \
	php7-phar \
	php7-posix \
	php7-redis \
	php7-sodium \
	php7-sqlite3 \
	php7-xmlreader \
	php7-zip \
	samba-client \
	sudo \
	tar \
	unzip && \
 echo "**** compile smbclient ****" && \
 git clone git://github.com/eduardok/libsmbclient-php.git /tmp/smbclient && \
 cd /tmp/smbclient && \
 phpize7 && \
 ./configure \
	--with-php-config=/usr/bin/php-config7 && \
 make && \
 make install && \
 echo "**** configure php and nginx for nextcloud ****" && \
 echo "extension="smbclient.so"" > /etc/php7/conf.d/00_smbclient.ini && \
 echo 'apc.enable_cli=1' >> /etc/php7/conf.d/apcu.ini && \
 sed -i \
	-e 's/;opcache.enable.*=.*/opcache.enable=1/g' \
	-e 's/;opcache.interned_strings_buffer.*=.*/opcache.interned_strings_buffer=8/g' \
	-e 's/;opcache.max_accelerated_files.*=.*/opcache.max_accelerated_files=10000/g' \
	-e 's/;opcache.memory_consumption.*=.*/opcache.memory_consumption=128/g' \
	-e 's/;opcache.save_comments.*=.*/opcache.save_comments=1/g' \
	-e 's/;opcache.revalidate_freq.*=.*/opcache.revalidate_freq=1/g' \
	-e 's/;always_populate_raw_post_data.*=.*/always_populate_raw_post_data=-1/g' \
	-e 's/memory_limit.*=.*128M/memory_limit=512M/g' \
		/etc/php7/php.ini && \
 sed -i \
	'/opcache.enable=1/a opcache.enable_cli=1' \
		/etc/php7/php.ini && \
 echo "env[PATH] = /usr/local/bin:/usr/bin:/bin" >> /etc/php7/php-fpm.conf && \
 echo "**** set version tag ****" && \
 if [ -z ${NEXTCLOUD_RELEASE+x} ]; then \
	NEXTCLOUD_RELEASE=$(curl -s https://raw.githubusercontent.com/nextcloud/nextcloud.com/master/strings.php \
	| awk -F\' '/VERSIONS_SERVER_FULL_STABLE/ {print $2;exit}'); \
 fi && \
 echo "**** download nextcloud ****" && \
 curl -o /app/nextcloud.tar.bz2 -L \
	https://download.nextcloud.com/server/releases/nextcloud-${NEXTCLOUD_RELEASE}.tar.bz2 && \
 echo "**** cleanup ****" && \
 apk del --purge \
	build-dependencies && \
 rm -rf \
	/tmp/*

# copy local files
COPY root/ /

# ports and volumes
EXPOSE 443
VOLUME /config /data

and gave access in my docker-compose:

version: '2'
volumes:
  resin-data:
services:
  nc:
    build: ./docker-nextcloud-master
    privileged: true
    network_mode: host
    devices:
     - '/dev:/dev'
    ports:
      - "443:443"
    volumes:
      - "resin-data:/data"
      - "resin-data:/config"

NextCloud boots up just fine but I am not able to see the folders where I mounted my drives at. I also enabled external storage and tried to add them via the extension I mounted them to and still a no-go. Any ideas?

I think you may start with a simpler setup for diagnosing the issue. You may run a single container without a docker-compose.yml file - it will be privileged. Then in your Dockerfile you may use our balenalib base images and only add the necessary commands for mounting one drive.

You should be able to add the fstab data from a command line shell to the container as well and execute the mount commands for testing from there.

It looks like you copied the fstab data directly from the example and it may not necessarily work for your case. You need to use blkid to see what the filesystem type is on the partitions you need to mount. You may try using the defaults fstab settings as well.

I the fstab settings are correct, both drives are formatted ext4 and my labels point to their respective locations in /dev. You may be answering one of the things I was getting confused with though which was about the base images. If I have already provisioned my devices with the raspberry pi4 image I mentioned in my initial post I still need to use a base image from the site inside of a container as well? I wanted to make sure I am understanding the distinction that these are two different things? I did try to edit the fstab information from command line when attached to the container and it gave me the read only error.

If I have already provisioned my devices with the raspberry pi4 image I mentioned in my initial post I still need to use a base image from the site inside of a container as well?

To clarify:

  • by “the raspberry pi4 image I mentioned in my initial post” you mean “the balenaOS 2.44.0+rev3 OS” you’ve flashed on the SD cards ?
  • what do you mean by “a base image from the site” ?

I’ll assume the response is yes for both questions above.

BalenaOS is the OS that runs on the hardware.
balenalib base images are base docker images that may help you building your own docker images.

You can use the base image you want as long as it exists for your architecture which seems to be the case for lsiobase/nginx:3.10.
However, we recommend using our balenalib base images for your containers.
In your case, I’d rename the Dockerfile to Dockerfile.template file and use FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:buster.
You can install nginx with apt-get as you do for the other stuff.

I did try to edit the fstab information from command line when attached to the container and it gave me the read only error.

  • How did you “attached to the container” ?
  • How did you edit /etc/fstab ?
  • What was the error precisely ?

Thank you Zvin, yes I was talking about the OS and you clarified the purpose of the base image. This was my misunderstanding what the purpose of the base images are used for but I get the use case now. I will try this how you recommended.

Also to clarify my comment about editing the fstab entry, I was logged into my balenaCloud and attached to the container that way. The error was that the fstab file was read only.

Let us know when you’ve tried one of the balenalib base images; bear in mind you’ll need to use an Alpine image if you’re going to mount the storage in the same way as you have tried above, other base image distributions will vary as explained in the docs.