Nextcloud, Technology, Tutorial, Ubuntu

SPINNING UP THE PODMAN NEXTCLOUD CONTAINER – TERMINAL-COPY-PASTE STYLE

What is this?

This post is kind of my original journey into podman and getting a quick proof-of-concept pod up and running. In the end I changed paths away from quadlets and terminal-pasting in favour of podman-compose (like docker compose) style setup because I like the neatness of the ‘recipe’ of a compose.yaml file. However, I am not done with the Quadlet journey as ultimately it seems like it’s the better way to do this on ubuntu.

Here are some links that are related to this post which could be helpful to skim before actually doing anything in this blog but if you want to just do what I did and do a bit of learning, this worked great:

Getting Nextcloud Going by Pasting a bunch of Stuff in the Terminal

This next entire part is based on THIS BLOG

1. Create Directory Structure for the POD

For the next part about creating the directories, he didn’t mention where these should be in the linux box. I will just put it in the home directory for now since that is a default landing place. It turned out to work just fine. These images are now out of date and actually the command to create systemd files is depreciated, but nonetheless a great and clear post to get yourself up to speed on pods and podman in general.

I will cd to my home directory and create a script that will create them all for me to speed it up and to match what he did. So basically I’ll paste this in and see if it works…it works. There is probably another way to do it but alas…

mkdir .podman && \
cd .podman && \
mkdir nextcloud && \
cd nextcloud && \
mkdir caddy && \
cd caddy && \
mkdir config && \
mkdir data && \
cd .. && \
mkdir mariadb && \
mkdir nextcloud && \
cd nextcloud && \
mkdir config && \
mkdir data && \
cd .. && \
mkdir backups && \
cd ~

It worked. It created the exact directory structure from the blog post.

2. Create the POD

Think about this part as creating the pod for the outside of the peas. Empty. Disappointing. Waiting to be filled with little podmen…

podman pod create \
--publish 80:80 \
--publish 443:443 \
--network slirp4netns:port_handler=slirp4netns \
nextcloud

Spat something like this back:

1807b61a5031cbd2e4dce4adb7d4fa46821ea1cdfbd9310bbae0bcaf2d92e6a7

That means the podd was successfully created, by the way. But just to confirm, I ran this to see if there were any pods podman pod ps, and there were.

Nextcloud empty pod is up and created.

3. Create the Database.

I will just copy and paste it in with my own two passwords swapped out:

podman run \
--detach \
--env MYSQL_DATABASE=nextcloud \
--env MYSQL_USER=nextcloud \
--env MYSQL_PASSWORD=superSecretPassword \
--env MYSQL_ROOT_PASSWORD=superSecretPassword \
--volume $HOME/.podman/nextcloud/mariadb:/var/lib/mysql:z \
--name mariadb \
--pod nextcloud \
docker.io/library/mariadb:11

“Trying to pull”
Got ‘server misbehaving’
What Went Wrong: Turns out I had messed up my default gateway in server settings and DNS wasn’t working. Worked nice after I did that change, ha. I discovered that with a standard ifconfig command to show what gateway the server was actually on.

Check if it’s up with podman ps

All good now. One podman in the pod. Continue…

4. Create the Nextcloud instance

Taking another copy-paste chunk from the blog and swapping out my password from the MYSQL_PASSWORD variable from the mariadb setup above:

podman run \
--detach \
--env MYSQL_HOST=mariadb \
--env MYSQL_DATABASE=nextcloud \
--env MYSQL_USER=nextcloud \
--env MYSQL_PASSWORD=superSecretPassword \
--volume $HOME/.podman/nextcloud/nextcloud/config:/var/www/html:z \
--volume $HOME/.podman/nextcloud/nextcloud/data:/var/www/html/data:z \
--name nextcloud-app \
--pod nextcloud \
docker.io/library/nextcloud:32-fpm

Note: The last line determines your image and your Nextcloud setup. Chose wisely.
Original from blog was this: docker.io/library/nextcloud:27-fpm but i upgraded to 32 since it had moved that far.

5. Create the Caddyfile to push data to the right places.

Made my CaddyFile into the appropriate directory we created above with sudo nano ~/.podman/nextcloud/caddy/config/Caddyfile

Pasted in his final config file and swapped out his domain with mine, left the rest verbatim:

yourDomain.duckdns.org {

    root * /var/www/html
    file_server
    php_fastcgi nextcloud_app:9000 {
        root /var/www/html
        env front_controller_active true
    }

    encode gzip

    log {
        output file /data/nextcloud-access.log
    }

    header {
        Strict-Transport-Security "max-age=15768000;includeSubDomains;preload"
    }

    # .htaccess / data / config / ... shouldn't be accessible from outside
    @forbidden {
        path /.htaccess
        path /data/*
        path /config/*
        path /db_structure
        path /.xml
        path /README
        path /3rdparty/*
        path /lib/*
        path /templates/*
        path /occ
        path /console.php
    }
    respond @forbidden 404

    redir /.well-known/carddav /remote.php/dav 301
    redir /.well-known/caldav /remote.php/dav 301
}

Not going to lie that I don’t know half of what even in that Caddyfile but someone does and it seems to work.

Gave it a quick read to make sure data saved into the file ok with: cat ~/.podman/nextcloud/caddy/config/Caddyfile

6. Launch the Caddy Podman Container

Ran his launching of the Caddy container with straight copy/paste and it worked fine:

podman run \
--detach \
--volume $HOME/.podman/nextcloud/nextcloud/config:/var/www/html:z \
--volume $HOME/.podman/nextcloud/caddy/config/Caddyfile:/etc/caddy/Caddyfile:z \
--volume $HOME/.podman/nextcloud/caddy/data:/data:z \
--name caddy \
--pod nextcloud \
docker.io/library/caddy:2

Checked with podman ps to make sure I could see all three containers, Plus the POD – Success

Ran curl localhost to make sure some Nextcloud like pages came up – Success

And, assuming your ports 80 / 443 are open on the server itself as per the notes above, you should be able to also now connect via a browser and get your Nextcloud login screen.

Nice! Operation Paste-to-Terminal is a success. Nextcloud is running and after really just a few copy-pastes.

What this does not address are:

  • How do you update a Nextcloud instance in this enviroment?
  • How do you backup?
  • How do you now move to Quadlet?
  • How do you move to podman-compose if you want?

But all of that will be for other posts. I will put this live so others can play along and learn.

Tagged , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *