I have a nextcloud setup like described here (docker-compose, let’s encrypt proxy companion, postgres and nextcloud). And for a while I couldn’t connect any new nextcloud clients to the installation.
This fixed it:
$CONFIG = array (
# manually added because it's not picked up from
# the env vars once set ... it seems ...
# the docker IP range
'trusted_proxies' => ["172.16.0.0/12"],
# the hostname of the server
'overwritehost' => "my.super.secret.server",
# the ENDUSER->PROXY protocol, NOT the proxy-> nextcloud protocol!
'overwriteprotocol' => "https",
# AAAND NOW back to the original config file ...
This is part 2 of a couple of blog posts about dokku, a amazing little Heroku clone.
In the previous post I showed how to set up Dokku on a DigitalOcean droplet, and deployed a little hello-world container with a single git push. The reason why I wanted dokku thoug was the need of a database. As said – hosting comes cheap, databases usually come either expensive or with limited flexibility, or just too annoying configuration effort.
Dokku is the perferct middle ground. Let’s see why.
For me it was the existing postgres plugin which you can simply install and use. The whole process is incredibly easy, takes wbout two commands, and looks like this (let’s assume our “hello world” container uses a database):
$ dokku postgres:create hello-world
dokku postgres:create hello-world
Waiting for container to be ready
Creating container database Securing connection to database
=====> Postgres container created: hello-world
=====> Container Information
Config dir: /var/lib/dokku/services/postgres/hello-world/config
Data dir: /var/lib/dokku/services/postgres/hello-world/data
Exposed ports: -
Internal ip: 172.17.0.9
Service root: /var/lib/dokku/services/postgres/hello-world
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cc99cccacf2c dokku/hello-world:latest "/bin/sh -c 'php-fpm…" 2 minutes ago Up 2 minutes 80/tcp hello-world.web.1
785ef252c748 postgres:10.2 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 5432/tcp dokku.postgres.hello-world
This creates a database container with postgres 10.2, as you can see. You can influence a lot of behavior by using environment variables, see the GitHub page for more info.
Then you link the container to the running app:
$ dokku postgres:link hello-world hello-world
-----> Setting config vars
-----> Restarting app hello-world
-----> Releasing hello-world (dokku/hello-world:latest)...
-----> Deploying hello-world (dokku/hello-world:latest)...
-----> Attempting to run scripts.dokku.predeploy from app.json (if defined)
-----> No Procfile found in app image
-----> DOKKU_SCALE file found (/home/dokku/hello-world/DOKKU_SCALE)
-----> Attempting pre-flight checks
For more efficient zero downtime deployments, create a file CHECKS.
See http://dokku.viewdocs.io/dokku/deployment/zero-downtime-deploys/ for examples
CHECKS file not found in container: Running simple container check...
-----> Waiting for 10 seconds ...
-----> Default container check successful!
-----> Running post-deploy
-----> Configuring hello-world.my-paas.for-myself.com...(using built-in template)
-----> Creating http nginx.conf
-----> Running nginx-pre-reload Reloading nginx
-----> Setting config vars DOKKU_APP_RESTORE: 1
-----> Found previous container(s) (14c349cb496d) named hello-world.web.1
=====> Renaming container (14c349cb496d) hello-world.web.1 to hello-world.web.1.1535285386
=====> Renaming container (cc99cccacf2c) serene_bassi to hello-world.web.1
-----> Attempting to run scripts.dokku.postdeploy from app.json (if defined)
-----> Shutting down old containers in 60 seconds
=====> Application deployed:
What happened? You have now the environment variable $DATABASE_URL set in the hello-world app, that’s why the restart was necessary (which you can postpone, if you want, but you probably need it now, right?).
$ docker exec -ti hello-world.web.1 /bin/sh
[now in the container]
# env | grep DATABASE
That’s it. Super easy. Now if you’re using Django, you could use kennethreitz/dj-database-url to automatically parse and use it, and you’re done. (Probably every framework has something similar, so just have a look).
I was looking for some “play” deployment method for a couple of things I want to try out. Most of them require a database. And it should be cheap, cause I don’t have any load on them and don’t earn any money, so I don’t want to spend basically no money if possible. The usual suspects are too expensive – AWS, Heroku, etc.
Dokku is a set of – hang on – shell scripts – which basically emulate Heroku on a machine of your own. It’s integrated with Digital Ocean droplets out of the box, if you want it. And the whole thing is 5 € / month, which is perfect. It also integrates with a Dockerfile based deployment, so you do git push and everything just works.
This is how you get started. But before you can get started, you need a domain you control, either on AWS or any other hoster. This is for routing traffic to your deployments later. You also need a public SSH key, or better a public / private key pair. Once you have both you can …
create a Digital Ocean account, and …
add your SSH public key to your account, and …
in that account, create a new droplet with a “Dokku” image preinstalled.
Wait until the droplet finished provisioning.
While the droplet is being created, you can also create a project locally to test it later:
In this little test project we only create a Dockerfile from an hello-world image which displays “Hello world” in a browser so we can verify it worked.
Once the droplet is done, you can start setting up your personal little PaaS. First, you have to configure your DNS. We will set up a wildcard entry for our deployments, and a non-wildcard entry for git. Let’s assume your domain is for-myself.com, then you would add …
my-paas.for-myself.com , type “A” (or “AAAA” if you are IPv6) to your droplet IP
*.my-paas.for-myself.com just the same
Then you SSH into your droplet, and create your dokku project. (This is something you have to do for every project). All you have to do for this is: