Docker Series Pt.1: How to Set up an ownCloud in 3 Minutes
Have you heard about Docker? It’s probably the easiest and most powerful way to setup ownCloud. Learn how to use docker-compose scripts to define and run your containers.
There are a multiple ways to install an ownCloud server. We already treated appliances in this blog, and the documentation covers a few more. This time you can learn about docker, the easiest and fastest way to install ownCloud.
You have probably heard of docker. It uses containers, not virtual machines. This is a more lightweight form of virtualization – where virtual machines emulate the whole kernel, docker only takes care of the operating system.
You don’t have to be a professional sysadmin or DevOps to use docker. It’s not bad to know some command line basics – but all in all you can get very fast results if you learn how to use it.
What is Docker?
docker (or docker-compose) is a very useful tool for docker containers – you can specify some settings in a .yml file, and use them to define and run a container.
Step by Step
To begin, login to labs.play-with-docker.com. docker-compose is preinstalled there, you can directly begin playing around. First, create a new instance with the button on the left.
Then, you can copy-paste this small command from the ownCloud-docker GitHub repository:
# Specify some settings via environment variables, save them in .env cat << EOF >| .env OWNCLOUD_VERSION=10.0.7 OWNCLOUD_DOMAIN=localhost ADMIN_USERNAME=admin ADMIN_PASSWORD=admin HTTP_PORT=80 HTTPS_PORT=443 EOF # Fetch the official ownCloud docker-compose file wget -O docker-compose.yml https://raw.githubusercontent.com/owncloud-docker/server/master/docker-compose.yml # Finally start the containers in the background docker-compose up -d
Execute the command and your ownCloud server is running. At the top of the play-with-docker interface you can now see two buttons, for port 80 and 443. They are links to your ownCloud login page.
The port 80 button will work out of the box. To use port 443, you have to add https:// in front of the URL and accept the self-signed certificate. It’s a known bug in play-with-docker.
passphrase=admin and voilà, you have a running ownCloud instance!
In docker-compose.yml files, you can use variables. The default variables are in the .env file. If you want changes to the container, you can edit them.
If you have already installed the docker container with these instructions, your .env file should look like this:
OWNCLOUD_VERSION=10.0.7 OWNCLOUD_DOMAIN=localhost ADMIN_USERNAME=admin ADMIN_PASSWORD=admin HTTP_PORT=80 HTTPS_PORT=443
Feel free to edit them with your favorite text editor, according to your needs. E.g. if you have a domain, you may want to use it in the .env file.
There are also some things in the docker-compose.yml which you may want to change. You should not use the default mariadb passphrases, for example.
When you are finished, you can apply the new settings by rebuilding the container – first delete it with “docker-compose down”, then restart it with “docker-compose up -d”.
Tip: you can view all your running and existing containers with the command “docker ps -a”.
And Where Exactly is my Data?
In the beginning of docker-compose.yml, docker volumes are defined. It looks like this:
volumes: files: driver: local mysql: driver: local
They are mounted inside the containers, to certain mountpoints:
services: owncloud: volumes: - files:/mnt/data
If you want to backup them, the volumes are on the host’s file system:
- Under Linux and MacOS: /var/lib/docker/volumes
- Under Windows: C:\ProgramData\docker\volumes
Upgrading the Docker Container
As soon as there is a new version of ownCloud, you can try to upgrade your ownCloud. In the example above, we deliberately left the version at 10.0.7, so we can try it out now.
When you upgrade an ownCloud in production, you should of course follow best upgrade practices: make backups before the upgrade, maybe even test it with a staging environment. You can read more about it in the documentation.
To upgrade our ownCloud container, change the version number in the .env file. It should be on 10.0.7 right now, the exact version. If you just want 10.0.8 or 10.0.9, you can enter their specific values. To skip this step in the future, you could also enter 10.0 for following all 10.0.x releases, or latest for any stable ownCloud server release.
To get the new version, you have to pull it with “docker-compose pull”. This downloads the version which you specified in the .env file.
Finally, recreate the existing container with “docker-compose up -d”. Voilà! You should have an upgraded ownCloud now. Note: all changes you made to the container itself will vanish. The volumes should stay though.
Can This Really Be That Easy?
Well, computers are complex. Docker is already reducing that complexity a lot. But of course, some problems can always arise. And trying to fix those problems is how you get better at administration and DevOps.
If you encounter problems with our instructions, let us know! Nobody is perfect. You can always ask for help in the comments, or even better, on Central.
Your Container, My Container
Of course you don’t have to use the official ownCloud docker container, or our docker-compose file. You should definitely play around with the docker-compose file, to find out what best suits your needs.
Using the official docker container has several advantages: the correct PHP version is used, the packages are up to date, and it gets tested by DevOps experts. On the other hand, the mariadb container in the docker-compose script is not officially supported.
Of course you can build your own container, if you need to. Or modify the official one – that’s the beauty of docker. So now, if you have not started yet – try it out!
Did you like this how-to? Share it on social media or leave a comment below. If you want to learn more about docker, stay tuned! This is the first part of a series about docker. More will follow in the next weeks!