A Comprehensive Guide to Deploying NextCloud on Podman
NextCloud, a powerful self-hosted cloud storage solution, can be deployed using various containerization tools. In recent years, Podman has gained popularity as an alternative to Docker due to its daemonless architecture. If you’re considering setting up NextCloud with Podman, this guide will help you navigate the installation and deployment process seamlessly.
Installing Podman on Ubuntu Server
Before diving into NextCloud, you need to establish Podman on your Ubuntu server. Begin by accessing your terminal within the Ubuntu environment. First, ensure your package listings are up-to-date by running:
sudo apt update
Next, upgrade any pending packages:
sudo apt upgrade -y
Now, install the Podman package along with its composer:
sudo apt install podman podman-compose
For versions of Ubuntu Server prior to 23.10, you’ll also need to install podman-compose
via pip
:
sudo apt install python3-pip
sudo pip3 install podman-compose
Once Podman is installed, verify its successful setup by executing:
podman --help
If this command works without issues, you’re ready to proceed.
Pulling the NextCloud Image
To install NextCloud, the first step is to pull the official image from Docker Hub. Use the following command in your terminal:
podman pull nextcloud
This process should be quick, allowing you to quickly move on to the database setup.
Pulling the MariaDB Image
NextCloud relies on a database to store its data, and using SQLite is strongly discouraged due to its instability. Therefore, you should pull the MariaDB image with:
podman pull mariadb
Installing CNI Plugins on Ubuntu
To maximize Podman’s capabilities, CNI (Container Network Interface) plugins must be installed. To simplify this process, you can use a bash script tailored for the job. Execute the following command to install the needed plugins:
curl -fsSL https://raw.githubusercontent.com/soltros/random-stuff/main/cni-tool.sh | bash
Deploying NextCloud with Podman
Now comes the exciting part—deploying your NextCloud instance. First, you’ll need to create volumes for your application and database data. Use the commands below:
podman volume create nc-app
podman volume create nc-data
podman volume create nc-db
Verify that your volumes were created successfully:
podman volume ls
Next, establish a network for your NextCloud containers:
podman network create nc-net
Creating Deployment Scripts
You will need two scripts to deploy your database and NextCloud application. First, create the database deployment script:
touch nc-podman-db-deploy.sh
nano nc-podman-db-deploy.sh
In the file, include the following script. Replace DB_USER_PASSWORD
and DB_ROOT_PASSWORD
with secure passwords you choose:
#!/bin/bash
podman run --detach \
--env MYSQL_DATABASE=nextcloud \
--env MYSQL_USER=nextcloud \
--env MYSQL_PASSWORD=DB_USER_PASSWORD \
--env MYSQL_ROOT_PASSWORD=DB_ROOT_PASSWORD \
--volume nc-db:/var/lib/mysql \
--network nc-net \
--restart on-failure \
--name nextcloud-db \
docker.io/library/mariadb:latest
Save and close the file (Ctrl + O, then Ctrl + X). Now, repeat the process for the NextCloud deployment script:
touch nc-podman-app-deploy.sh
nano nc-podman-app-deploy.sh
Include the following code in the new script, ensuring you adjust DB_USER_PASSWORD
, NC_ADMIN
, and NC_PASSWORD
as necessary:
#!/bin/bash
podman run --detach \
--env MYSQL_HOST=nextcloud-db.dns.podman \
--env MYSQL_DATABASE=nextcloud \
--env MYSQL_USER=nextcloud \
--env MYSQL_PASSWORD=DB_USER_PASSWORD \
--env NEXTCLOUD_ADMIN_USER=NC_ADMIN \
--env NEXTCLOUD_ADMIN_PASSWORD=NC_PASSWORD \
--volume nc-app:/var/www/html \
--volume nc-data:/var/www/html/data \
--network nc-net \
--restart on-failure \
--name nextcloud \
--publish 8080:80 \
docker.io/library/nextcloud:latest
After saving, you can deploy the scripts as follows:
bash nc-podman-db-deploy.sh
bash nc-podman-app-deploy.sh
Update the containers with the following commands:
podman exec -u root -it nextcloud apt update
podman exec -u root -it nextcloud apt upgrade
podman exec -u root -it nextcloud apt install nano
Now, edit the config.php
file to ensure it’s set up correctly:
podman exec -u root -it nextcloud nano /var/www/html/config/config.php
Change the instance’s trusted domain from localhost
to your server’s domain name. For example, if your server domain is ubuntu-server-vm
, make that update.
Once finished, save and exit. Restart the NextCloud container with:
podman container restart nextcloud
Now, you’re ready to access your NextCloud installation using the admin credentials you’ve set.
Managing Your Containers
To manage your NextCloud and database containers, use the following commands to start, stop, or restart as needed:
podman container start nextcloud
podman container start nextcloud-db
podman container stop nextcloud
podman container stop nextcloud-db
podman container restart nextcloud
podman container restart nextcloud-db
With this straightforward guide, you can successfully deploy and manage NextCloud using Podman. Enjoy your secure and customizable cloud storage experience!