{"id":773,"date":"2018-11-06T18:59:23","date_gmt":"2018-11-06T16:59:23","guid":{"rendered":"https:\/\/lisas.de\/~adrian\/posts\/2018-Nov-06-nextcloud-in-a-container.html"},"modified":"2026-03-30T22:41:24","modified_gmt":"2026-03-30T20:41:24","slug":"nextcloud-in-a-container","status":"publish","type":"post","link":"https:\/\/lisas.de\/luges\/index.php\/2018\/11\/06\/nextcloud-in-a-container\/","title":{"rendered":"Nextcloud in a Container"},"content":{"rendered":"<p>After using Podman a lot during the last weeks while adding <a class=\"reference external\" href=\"https:\/\/podman.io\/blogs\/2018\/10\/10\/checkpoint-restore.html\">checkpoint\/restore support to Podman<\/a> I was finally ready to use containers in production on our <a class=\"reference external\" href=\"https:\/\/ftp-stud.hs-esslingen.de\/info\/\">mirror server<\/a>. We were still running the ownCloud version that came via RPMs in Fedora 27 and it seems like many people have moved on to Nextcloud from tarballs.<\/p>\n<p>One of the main reason to finally use containers is Podman&#8217;s daemonless approach.<\/p>\n<p>The first challenge while moving from ownCloud 9.1.5 to Nextcloud 14 is the actual upgrade. To make sure it works I first made a copy of all the uploaded files and of the database and did a test upgrade yesterday using a CentOS 7 VM. With PHP 7 from Software Collections it was not a real problem. It took some time, but it worked. I used the included upgrade utility to upgrade from ownCloud 9 to Nextcloud 10, to Nextcloud 11, to Nextcloud 12, to Nextcloud 13, to Nextcloud 14. Lots of upgrades. Once I verified that everything was still functional I did it once more, but this time I used the real data and disabled access to our ownCloud instance.<\/p>\n<p>The next step was to start the container. I decided to use the <tt class=\"docutils literal\">nextcloud:fpm<\/tt> container as I was planning to use the existing web server to proxy the requests. The one thing which makes using containers on our mirror server a bit difficult, is that it is not possible to use any <tt class=\"docutils literal\">iptables<\/tt> NAT rules. At some point there are just too many network connections in the NAT table from all the clients connecting to our mirror server that it used to drop network connections. This is a problem which is probably fixed since a long time, but it used to be a problem and I try to avoid it. That is why my Nextcloud container is using the host network namespace:<\/p>\n<div class=\"highlight\">\n<pre><span><\/span>podman<span class=\"w\"> <\/span>run<span class=\"w\"> <\/span>--name<span class=\"w\"> <\/span>nextcloud-fpm<span class=\"w\"> <\/span>-d<span class=\"w\"> <\/span>--net<span class=\"w\"> <\/span>host<span class=\"w\"> <\/span><span class=\"se\"><\/span> <span class=\"w\"> <\/span>-v<span class=\"w\"> <\/span>\/home\/containers\/nextcloud\/html:\/var\/www\/html<span class=\"w\"> <\/span><span class=\"se\"><\/span> <span class=\"w\"> <\/span>-v<span class=\"w\"> <\/span>\/home\/containers\/nextcloud\/apps:\/var\/www\/html\/custom_apps<span class=\"w\"> <\/span><span class=\"se\"><\/span> <span class=\"w\"> <\/span>-v<span class=\"w\"> <\/span>\/home\/containers\/nextcloud\/config:\/var\/www\/html\/config<span class=\"w\"> <\/span><span class=\"se\"><\/span> <span class=\"w\"> <\/span>-v<span class=\"w\"> <\/span>\/home\/containers\/nextcloud\/data:\/var\/www\/html\/data<span class=\"w\"> <\/span><span class=\"se\"><\/span> <span class=\"w\"> <\/span>nextcloud:fpm <\/pre>\n<\/div>\n<p>I was reusing my existing <tt class=\"docutils literal\">config.php<\/tt> in which the connection to PostgreSQL on <tt class=\"docutils literal\">127.0.0.1<\/tt> was still configured.<\/p>\n<p>Once the container was running I <em>just<\/em> had to add the proxy rules to the Apache HTTP Server and it should have been ready. Unfortunately this was not as easy as I hoped it to be. All the documentation I found is about using the <a class=\"reference external\" href=\"https:\/\/github.com\/nextcloud\/docker\">Nextcloud FPM container<\/a> with NGINX. I found nothing about Apache&#8217;s HTTPD. The following lines required most of the time of the whole upgrade to Nextcloud project:<\/p>\n<div class=\"highlight\">\n<pre><span><\/span><span class=\"nt\">&lt;FilesMatch<\/span><span class=\"w\"> <\/span><span class=\"s\">.php.*<\/span><span class=\"nt\">&gt;<\/span> <span class=\"w\"> <\/span><span class=\"nb\">SetHandler<\/span><span class=\"w\"> <\/span>proxy:fcgi:\/\/127.0.0.1:9000\/ <span class=\"w\"> <\/span><span class=\"nb\">ProxyFCGISetEnvIf<\/span><span class=\"w\"> <\/span><span class=\"s2\">&quot;reqenv(&#039;REQUEST_URI&#039;) =~ m|(\/owncloud\/)(.*)$|&quot;<\/span><span class=\"w\"> <\/span>SCRIPT_FILENAME<span class=\"w\"> <\/span><span class=\"s2\">&quot;\/var\/www\/html\/$2&quot;<\/span> <span class=\"w\"> <\/span><span class=\"nb\">ProxyFCGISetEnvIf<\/span><span class=\"w\"> <\/span><span class=\"s2\">&quot;reqenv(&#039;REQUEST_URI&#039;) =~ m|^(.+.php)(.*)$|&quot;<\/span><span class=\"w\"> <\/span>PATH_INFO<span class=\"w\"> <\/span><span class=\"s2\">&quot;$2&quot;<\/span> <span class=\"nt\">&lt;\/FilesMatch&gt;<\/span> <\/pre>\n<\/div>\n<p>I hope these lines are actually correct, but so far all clients connecting to it seem to be happy. To have the Nextcloud container automatically start on system startup I based my systemd podman service file on the one from the <a class=\"reference external\" href=\"https:\/\/developers.redhat.com\/blog\/2018\/08\/29\/intro-to-podman\/\">Intro to Podman article<\/a>.<\/p>\n<div class=\"highlight\">\n<pre><span><\/span><span class=\"k\">[Unit]<\/span> <span class=\"na\">Description<\/span><span class=\"o\">=<\/span><span class=\"s\">Custom Nextcloud Podman Container<\/span> <span class=\"na\">After<\/span><span class=\"o\">=<\/span><span class=\"s\">network.target<\/span> <span class=\"k\">[Service]<\/span> <span class=\"na\">Type<\/span><span class=\"o\">=<\/span><span class=\"s\">simple<\/span> <span class=\"na\">TimeoutStartSec<\/span><span class=\"o\">=<\/span><span class=\"s\">5m<\/span> <span class=\"na\">ExecStartPre<\/span><span class=\"o\">=<\/span><span class=\"s\">-\/usr\/bin\/podman rm nextcloud-fpm<\/span> <span class=\"na\">ExecStart<\/span><span class=\"o\">=<\/span><span class=\"s\">\/usr\/bin\/podman run --name nextcloud-fpm --net host <\/span> <span class=\"w\"> <\/span><span class=\"s\">-v \/home\/containers\/nextcloud\/html:\/var\/www\/html <\/span> <span class=\"w\"> <\/span><span class=\"s\">-v \/home\/containers\/nextcloud\/apps:\/var\/www\/html\/custom_apps <\/span> <span class=\"w\"> <\/span><span class=\"s\">-v \/home\/containers\/nextcloud\/config:\/var\/www\/html\/config <\/span> <span class=\"w\"> <\/span><span class=\"s\">-v \/home\/containers\/nextcloud\/data:\/var\/www\/html\/data <\/span> <span class=\"w\"> <\/span><span class=\"s\">nextcloud:fpm<\/span> <span class=\"na\">ExecReload<\/span><span class=\"o\">=<\/span><span class=\"s\">\/usr\/bin\/podman stop nextcloud-fpm<\/span> <span class=\"na\">ExecReload<\/span><span class=\"o\">=<\/span><span class=\"s\">\/usr\/bin\/podman rm nextcloud-fpm<\/span> <span class=\"na\">ExecStop<\/span><span class=\"o\">=<\/span><span class=\"s\">\/usr\/bin\/podman stop nextcloud-fpm<\/span> <span class=\"na\">Restart<\/span><span class=\"o\">=<\/span><span class=\"s\">always<\/span> <span class=\"na\">RestartSec<\/span><span class=\"o\">=<\/span><span class=\"s\">30<\/span> <span class=\"k\">[Install]<\/span> <span class=\"na\">WantedBy<\/span><span class=\"o\">=<\/span><span class=\"s\">multi-user.target<\/span> <\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>After using Podman a lot during the last weeks while adding checkpoint\/restore support to Podman I was finally ready to use containers in production on our mirror server. We were still running the ownCloud version that came via RPMs in Fedora 27 and it seems like many people have moved on to Nextcloud from tarballs. [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-773","post","type-post","status-publish","format-standard","hentry","category-luges"],"_links":{"self":[{"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts\/773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/comments?post=773"}],"version-history":[{"count":19,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts\/773\/revisions"}],"predecessor-version":[{"id":1912,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts\/773\/revisions\/1912"}],"wp:attachment":[{"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/media?parent=773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/categories?post=773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/tags?post=773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}