Skip to content

Instantly share code, notes, and snippets.

Last active September 8, 2019 14:46
Show Gist options
  • Save renevo/6a9e244b670df334c42578b8fe95400b to your computer and use it in GitHub Desktop.
Save renevo/6a9e244b670df334c42578b8fe95400b to your computer and use it in GitHub Desktop.
Nextcloud - Cloud-Init with Docker
version: '3'
image: nextcloud
- 80:80
- nextcloud:/var/www/html
- /var/cloud/data:/var/www/html/data
restart: always
apt-get install pv unzip hdparm
curl -O$(uname -s)/flash
chmod +x flash
sudo mv flash /usr/local/bin/flash
# Download this yaml from this repo
rm ./user-data.yml
curl -O
flash \
--hostname \
--userdata ./user-data.yml \
# vim: syntax=yaml
# The current version of cloud-init in the Hypriot rpi-64 is 0.7.9
# When dealing with cloud-init, it is SUPER important to know the version
# I have wasted many hours creating servers to find out the module I was trying to use wasn't in the cloud-init version I had
# Documentation:
# Set your hostname here, the manage_etc_hosts will update the hosts file entries as well
hostname: nextcloud-pi64
manage_etc_hosts: true
# This expands the root volume to the entire SD Card, similar to what the raspbian images did on first boot.
# This doesn't seem to be required, its more here for posterity in understanding what is going on
resize_rootfs: true
mode: auto
devices: ["/"]
ignore_growroot_disabled: false
# You could modify this for your own user information
- name: pirate
gecos: "Hypriot Pirate"
shell: /bin/bash
groups: users,docker,video
plain_text_passwd: hypriot
lock_passwd: false
ssh_pwauth: true
chpasswd: { expire: false }
# Update our packages on first boot, saves us some time
package_update: true
package_upgrade: true
package_reboot_if_required: true
# Install any additional packages you need here
# I add ntp because.. without it, rpi is useless in keeping track of time.
- ntp
# Set the locale of the system
locale: "en_US.UTF-8"
# Set the timezone
# Value of 'timezone' must exist in /usr/share/zoneinfo
timezone: "America/Los_Angeles"
# Tell docker to tag this node appropriately
# Currently we need the experimental?
- path: "/etc/docker/daemon.json"
owner: "root:root"
content: |
"labels": [ "os=linux", "arch=arm64" ],
"experimental": true
# These commands will be ran once on first boot only
# Pickup the hostname changes
- [ systemctl, restart, avahi-daemon ]
# Pickup the daemon.json changes
- [ systemctl, restart, docker ]
# Init a swarm, because why not
- [docker, swarm, init ]
# Run portainer, so we can see our logs and control stuff from a UI
- [
docker, service, create,
"--name", "portainer",
"--publish", "9000:9000",
"--mount", "type=volume,src=portainer_data,dst=/data",
"--mount", "type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock",
"portainer/portainer", "-H", "unix:///var/run/docker.sock", "--no-auth"
# Create a specific directory to store all the data, this way you could mount an external drive later (coming soon!)
- [mkdir, "-p", "/var/cloud/data" ]
# This gives the nextcloud permissions to write to this directory since it runs as www-data
- [setfacl, "-m", "u:www-data:rwx", "/var/cloud/data" ]
# Create the nextcloud instance configuring it on startup - you should change the user/password below to something less obvious or use the config UI
- [
docker, service, create,
"--name", "nextcloud",
"--publish", "80:80",
"--mount", "type=volume,src=nextcloud,dst=/var/www/html",
"--mount", "type=bind,src=//var/cloud/data,dst=/var/www/html/data",
"--env", "SQLITE_DATABASE=nextcloud",
"--env", "NEXTCLOUD_ADMIN_USER=pirate",
"--env", "NEXTCLOUD_ADMIN_PASSWORD=hypriot",
Copy link

Reading your blog post, and being a Docker noob trying to get a custom image: what's the difference between using cloud-init and creating a Docker image by writing Dockerfiles?

Copy link

@renevo Having some trouble reproducing your setup. It seems that Portainer is only run on first boot. After rebooting, it must be manually restarted. Any suggestions?

Copy link

renevo commented Feb 20, 2019

@breandan that should have been started back up due to it being a docker service, not a standard container. Are you sure that docker swarm init succeeded?

Copy link

johnwyles commented Mar 18, 2019

@renevo I have been trying to bootstrap your project with Hypriot 1.10 configuring wifi instead of the ethernet interfaces. I was trying to start with this guide: but found that I needed to back-step to this page for an example user-data: Basically by placing that section in the wifi.yml to pass to flash I do see that the /etc/wpa_supplicant/wpa_supplicant.conf file is updated and has the correct information in it - however the interface does not look to be using any of the settings with a check of ifconfig to see an associated IP (I am, of course, able to tell this by plugging in an ethernet cable to get to the box and verifying the contents of the file). Are there more example user-data files / yml that use the RPi wifi for a kubernetes cluster?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment