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 -h 10.1.1.160 -u root -p rockylinux << eof
create 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:
vidb-drop.sh
Copy and paste this code into the new file:
#!/bin/bash
mysql -h 10.1.1.160 -u root -p rockylinux << eof
drop database ncdb;
flush privileges;
eof
Lastly, setup the DockerFile for the db-tools image:
viDockerfile
Copy and paste:
FROM localhost/base
RUN yum -y install mysql
WORKDIR /root
COPY db-drop.sh db-drop.sh
COPY db-create.sh db-create.sh
And last but not least, create the bash script to build your image on command:
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.
Save and close that out, make all of your scripts executable, then run the image building script first:
chmod+x*.sh
./build.sh
To ensure all of your images have been built correctly, run podman images. You should see a list that looks like this:
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
If it all looks right, run the final script to get Nextcloud up and going:
./run.sh
When you run podman ps -a, you should see a list of running containers that looks like this:
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
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