This document explains all the required steps needed to build and run a Nextcloud instance as a Podman container on Rocky Linux. What is more, this entire guide was tested on a Raspberry Pi, so it should be compatible with every Rocky-supported processor architecture.
The procedure is broken down into multiple steps, each with its own shell scripts for automation:
Installing the podman and buildah packages to manage and build our containers, respectively
Creating a base image that will be repurposed for all of the containers we will need
Creating a db-tools container image with the required shell scripts for building and running your MariaDB database
Creating and running MariaDB as a Podman container
Creating and running Nextcloud as a Podman container, using the MariaDB Podman container as backend
You could run most of the commands in the guide manually, but setting up a few bash scripts will make your life much easier, especially when you want to repeat these steps with different settings, variables, or container names.
Note for Beginners:
Podman is a tool for managing containers, specifically OCI (Open Containers Initiative) containers. It is designed to be pretty much Docker-compatible, in that most if not all of the same commands will work for both tools. If "Docker" means nothing to you—or even if you were just curious—you can read more about Podman and how it works on Podman's own website.
buildah is a tool that builds Podman container images based on "DockerFiles".
This guide was designed as an exercise to help people get familiar with running Podman containers in general, and on Rocky Linux specifically.
For the purposes of this guide, we are keeping the database setup as simple as we can. You will want to keep track of the following, and modify them as needed:
Database name: ncdb
Database user: nc-user
Database pass: nc-pass
Your server IP address (we will be using an example IP below)
First, change to the folder where you will be building the db-tools image:
cd/root/db-tools
Now set up some bash scripts that will be used inside the Podman container image. First, make the script that will automatically build your database for you:
vidb-create.sh
Now copy and paste the following code into that file, using your favorite text editor:
#!/bin/bash
mysql-h10.1.1.160-uroot-prockylinux<< eofcreate database ncdb;grant all on ncdb.* to 'nc-user'@'10.1.1.160' identified by 'nc-pass';flush privileges;eof
Save and close, then repeat the steps with the script for deleting databases as needed:
You are getting the hang of the process, right? It is time to build that actual database container. Change the working directory to /root/mariadb:
cd/root/mariadb
Make a script to (re)build the container whenever you want:
vidb-init.sh
And here is the code you will need:
Warning
For the purposes of this guide, the following script will delete all Podman Volumes. If you have other applications running with their own volumes, modify/comment the line "podman volume rm --all";
Now, we are going to set up a bunch of local folders on the host server (not in any Podman container), so that we can rebuild our containers and databases without fear of losing all of our files:
Lastly, we are going to create the script that will actually build the Nextcloud container for us:
virun.sh
And here is all the code you need for that. Ensure you change the IP address for MYSQL_HOST to the docker container that is running your MariaDB instance.
From there, you should be able to point your browser to your server IP address. If you are following along and have the same IP as our example, you can substitute that in here (e.g., http://your-server-ip) and see Nextcloud up and running.
Obviously, this guide would have to be somewhat modified on a production server, especially if the Nextcloud instance is intended to be public-facing. Still, that should give you a basic idea of how Podman works, and how you can set it up with scripts and multiple base images to make rebuilds easier.
Author: Ananda Kammampati
Contributors: Ezequiel Bruni, Steven Spencer, Ganna Zhyrnova