Nextcloud with podman on Raspberry Pi4 running Rocky Linux 8.5

Author: Ananda Kammampati

Dated: March 2022

Scope:

  • To build and run Nextcloud as podman containers on Raspberry Pi4 running Rocky Linux 8.5
  • To showcase and share simple shell scripts in building podman containers

Source of Inspiration:

Out of Scope:

  • Full configuration and administration of Nextcloud

Video:

  • Scroll to the end for a video on installation screenshots
Raspberry Pi4

Step 01: Install podman, buildah

# uname -a
Linux worker 5.15.21-v8.1.el8 #1 SMP PREEMPT Thu Feb 24 20:09:47 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

# more /etc/*release
::::::::::::::
/etc/centos-release
::::::::::::::
Rocky Linux release 8.5 (Green Obsidian)
::::::::::::::
/etc/os-release
::::::::::::::
NAME="Rocky Linux"
VERSION="8.5 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.5"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.5 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"
::::::::::::::
/etc/redhat-release
::::::::::::::
Rocky Linux release 8.5 (Green Obsidian)
::::::::::::::
/etc/rocky-release
::::::::::::::
Rocky Linux release 8.5 (Green Obsidian)
::::::::::::::
/etc/system-release
::::::::::::::
Rocky Linux release 8.5 (Green Obsidian)

# dnf -y epel-release ; yum -y update ; sync ; reboot

# dnf -y podman buildah

# podman --version
podman version 3.4.2

# buildah --version
buildah version 1.23.1 (image-spec 1.0.1-dev, runtime-spec 1.0.2-dev)

# vi /etc/containers/registries.conf 
~~~~~
[registries.insecure]
registries = ['registry.access.redhat.com', 'registry.redhat.io', 'docker.io'] 
insecure = true 
~~~~~

Step 02: Create base container image

# cd /root

# mkdir base db-tools mariadb nextcloud

# cd /root/base

# vi Dockerfile
~~~~~
FROM rockylinux/rockylinux:latest
ENV container docker
RUN yum -y install epel-release ; yum -y update
RUN dnf module enable -y php:7.4
RUN dnf install -y php
RUN yum install -y bzip2 lsof ; yum -y update
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done);
rm -f /lib/systemd/system/multi-user.target.wants/*; rm -f /etc/systemd/system/*.wants/*; rm -f /lib/systemd/system/local-fs.target.wants/*; rm -f /lib/systemd/system/sockets.target.wants/*udev*; rm -f /lib/systemd/system/sockets.target.wants/*initctl*; rm -f /lib/systemd/system/basic.target.wants/*; rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]
~~~~~

# vi build.sh
~~~~~
#!/bin/bash
clear
buildah rmi `buildah images -q base` ;
buildah bud --no-cache -t base . ;
buildah images -a
~~~~~

# chmod +x build.sh

# ./build.sh

Step 03: Create db-tools container image  

Database Details:
~~~~~
Database name:ncdb
Database user:nc-user
Database pass:nc-pass
IP Address:10.1.1.160 (Change the IP address according to your setup)
~~~~~

# cd /root/db-tools

# vi db-create.sh
~~~~~
#!/bin/bash
mysql -h10.1.1.160 -u root -prockylinux << eof
create database ncdb;
grant all on ncdb.* to 'nc-user'@'10.1.1.160' identified by 'nc-pass';
flush privileges;
eof
~~~~~

# vi db-delete.sh
~~~~~
#!/bin/bash
mysql -h10.1.1.160 -u root -prockylinux << eof
drop database ncdb;
flush privileges;
eof
~~~~~

# vi Dockerfile
~~~~~
FROM localhost/base
RUN yum -y install mysql
WORKDIR /root
COPY db-drop.sh db-drop.sh
COPY db-create.sh db-create.sh
~~~~~

# vi build.sh
~~~~~
#!/bin/bash
clear
buildah rmi `buildah images -q db-tools` ;
buildah bud --no-cache -t db-tools . ;
buildah images -a
~~~~~

# chmod +x build.sh

# ./build.sh

Step 04: Create mariadb container image 

# cd /root/mariadb

NOTE: We are deleting all the Volumes. If you have other applications running with their own volumes, modify/comment the line "podman volume rm --all"

# vi db-init.sh
~~~~
#!/bin/bash
clear
echo " "
echo "Deleting existing volumes if any...."
podman volume rm --all ;
echo " "
echo "Starting mariadb container....."
podman run --name mariadb --label mariadb -d --net host -e MYSQL_ROOT_PASSWORD=rockylinux -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v mariadb-data:/var/lib/mysql/data:Z mariadb ;

echo " "
echo "Initializing mariadb (takes 2 minutes)....."
sleep 120 ;

echo " "
echo "Creating ncdb Database for nextcloud ....."
podman run --rm --net host db-tools /root/db-create.sh ;

echo " "
echo "Listing podman volumes...."
podman volume ls
~~~~~

# vi db-reset.sh
~~~~~
#!/bin/bash
clear
echo " "
echo "Deleting ncdb Database for nextcloud ....."
podman run --rm --net host db-tools /root/db-drop.sh ;

echo " "
echo "Creating ncdb Database for nextcloud ....."
podman run --rm --net host db-tools /root/db-create.sh ;
~~~~~

# vi build.sh
~~~~~
#!/bin/bash
clear
buildah rmi `buildah images -q mariadb` ;
buildah bud --no-cache -t mariadb . ;
buildah images -a
~~~~~

# vi Dockerfile
~~~~~
FROM arm64v8/mariadb
~~~~~

# chmod +x *.sh

# ./build.sh

Step 05: Build and Run Nextcloud container

# cd /root/nextcloud

# vi Dockerfile
~~~~~
FROM arm64v8/nextcloud
~~~~~

# vi build.sh
~~~~~
#!/bin/bash
clear
buildah rmi `buildah images -q nextcloud` ;
buildah bud --no-cache -t nextcloud . ;
buildah images -a
~~~~~

# mkdir -p /usr/local/nc/nextcloud /usr/local/nc/apps /usr/local/nc/config /usr/local/nc/data

# vi run.sh
~~~~~
#!/bin/bash
clear
echo " "
echo "Starting nextloud container....."
podman run --name nextcloud --net host --privileged -d -p 80:80 \
-e MYSQL_HOST=10.1.1.160 \
-e MYSQL_DATABASE=ncdb \
-e MYSQL_USER=nc-user \
-e MYSQL_PASSWORD=nc-pass \
-e NEXTCLOUD_ADMIN_USER=admin \
-e NEXTCLOUD_ADMIN_PASSWORD=rockylinux \
-e NEXTCLOUD_DATA_DIR=/var/www/html/data \
-e NEXTCLOUD_TRUSTED_DOMAINS=10.1.1.160 \
-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
-v /usr/local/nc/nextcloud:/var/www/html \
-v /usr/local/nc/apps:/var/www/html/custom_apps \
-v /usr/local/nc/config:/var/www/html/config \
-v /usr/local/nc/data:/var/www/html/data \
nextcloud ;
~~~~~

# chmod +x *.sh

# ./build.sh

# podman images
~~~~~
REPOSITORY                      TAG    IMAGE ID     CREATED      SIZE
localhost/db-tools              latest 8f7ccb04ecab 6 days ago   557 MB
localhost/base                  latest 03ae68ad2271 6 days ago   465 MB
docker.io/arm64v8/mariadb       latest 89a126188478 11 days ago  405 MB
docker.io/arm64v8/nextcloud     latest 579a44c1dc98 3 weeks ago  945 MB
docker.io/rockylinux/rockylinux latest 7053cf983138 3 months ago 247 MB
~~~~~

# ./run.sh

# podman ps -a
~~~~~
CONTAINER ID IMAGE                              COMMAND              CREATED        STATUS            PORTS    NAMES
9518756a259a docker.io/arm64v8/mariadb:latest   mariadbd             3 minutes  ago Up 3 minutes ago           mariadb
32534e5a5890 docker.io/arm64v8/nextcloud:latest apache2-foregroun... 12 seconds ago Up 12 seconds ago          nextcloud
~~~~~

Point your browser to http://10.1.1.160

nextcloud