How to Run Nextcloud in Docker Container

Hello everyone, welcome to another tutorial of Docker. In this article, we are going to learn how to run Nextcloud in Docker. As you know, Nextcloud is a great software that offers many features to build a personal cloud storage and sharing service. There are several ways to run Nextcloud on our server. You can install it on a dedicated server, a virtual machine (VMWare, VirtualBox), cloud computer (Amazon EC2, Linode, Digital Ocean etc.). Another option that can be used is using Docker.

To run Nextcloud on Docker container, there are some simple steps that we need to take care of. First thing first, we will need Docker installed in our system. You can use Windows or Linux to install Docker. In this example, we are going to run a Nextcloud instance and a MySQL Server. Make sure Docker is installed and running properly on your system. Run this command to check the Docker version.

[oracle@server ~]$ sudo docker --version
[sudo] password for oracle:
Docker version 18.09.1, build 4c52b90

OK, so let’s continue to the next step.

Prerequisites

There are several things we need to prepare in order to run Nextcloud in a Docker container.

  1. Internet connection
  2. Basic Terminal command experiences are needed
  3. A single MySQL docker container >> We will create this later
  4. My Docker host IP address: 192.168.100.99 >> Make a note of your Docker host IP address.

Step 1. Create a new MySQL Container

We will use the MySQL database to store the Nextcloud tables. You can use SQLite or PostgreSQL but in this tutorial, we are going to use MySQL Server. So first, let’s run a new MySQL Container in Docker.

[oracle@server ~]$ sudo docker run -p 33060:3306 --name mysql-server -e MYSQL_ROOT_PASSWORD=12345 -e MYSQL_ROOT_HOST=% -d mysql/mysql-server:latest

Modify the command if you want to change the container name (mysql-server) and port number (33060). Confirm the new MySQL Server container:

[oracle@server ~]$ sudo docker ps
[sudo] password for oracle:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
27a91e9ea75e mysql/mysql-server:latest "/entrypoint.sh mysq…" 4 hours ago Up 2 hours (healthy) 33060/tcp, 0.0.0.0:33060->3306/tcp mysql-server
e99c42874973 portainer/portainer "/portainer" 12 days ago Up 2 hours 0.0.0.0:9000->9000/tcp reverent_bell

As you can see, our new MySQL server container is up and running at port 33060. At this point, my MySQL Server is up and running

Create a New Database and User

Login to the mysql-server container using exec command. And then login to MySQL.

sudo docker exec -it mysql-server /bin/bash

For example:

[oracle@server ~]$ sudo docker exec -it mysql-server /bin/bash
bash-4.2# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 395
Server version: 8.0.15 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

Create a new database

mysql> CREATE DATABASE nextcloud;
Query OK, 1 row affected (0.08 sec)

Create a new user

CREATE USER 'dhani'@'%' IDENTIFIED WITH mysql_native_password BY '12345';

Please make sure you use the mysql_native_password option when creating new user. Otherwise, you will not be able to connect to it during Nextcloud installation. This option will bypass the new caching_sha2_password authentication in new MySQL version.

Grant Privileges

mysql> GRANT ALL PRIVILEGES ON nextcloud.* TO 'dhani'@'%';

Now you can exit from mysql console and exit from the container command prompt.

Step 2. Create a New Nextcloud Container

Now we are ready to create a new Nextcloud container. Use and modify the following command

[oracle@server ~]$ sudo docker run --name nextcloud01 --link mysql-server:mysql -d -p 8080:80 nextcloud
[sudo] password for oracle:
d3ea0f86801e792015a92908cbdefbc1366e984d2822d5796b3cf9ab65785755

Now open a web browser and type the Docker host IP address followed by 8080

http://192.168.100.99:8383

You will see the following screen. We need to create a new admin user for Nextcloud.

You may change the data folder but in this case, I leave it as is. Next, choose MySQL/MariaDB as shown above.

Enter the MySQL database user and password, database name and host. As you can see, my Database Host is : 192.168.100.99:33060. Click Finish Setup to complete the installation.

On a successful installation, you will see the following window on your browser.

For more information, please visit the following links:

Be the first to comment

Leave a Reply