[DOCKER] Play down with Raspberry PI4 as a server. Part 2

This article is the 19th day article of Voicy Advent Calendar 2020. The day before, @ somen440's [golang] orchestration-based saga pattern is a gentle introduction. . Tomorrow is @ moonum's ~.

Introduction

This article is a continuation of this article on Day 11. Play with Raspberry PI4 as a server. Part 1 The content is to use RaspberryPi4 as a server and operate it, but last time, I introduced Openmediavault to RaspberryPi4, set up NAS, and installed Docker to build the server. This time, I will write about building cloud storage and streaming server using installed Docker.

Cloud storage

This time, we will use NextCloud for cloud storage. Since NextCloud is OSS, there is no usage fee, and there is also an external storage linkage function, so it is a big advantage that you can effectively use existing storage.

Preparation for introduction

Since PGID and PUID are required for docker settings, log in to Raspberry Pi with SSH and check PGID and PUID. If it is the default account and host name

ssh [email protected]

You can connect with.

After connecting, check with the id command. Use uid as PUID and gid as PGID.

id
uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),105(input),109(netdev),111(ssh),997(gpio),998(i2c),999(spi)

Installation

To install NextCloud, you first need to set up the DB used by NextCloud. MariaDB will be used as the DB.

Get MariaDB and NextCloud Docker-compose from Docker Hub. https://hub.docker.com//mariadb https://hub.docker.com//nextcloud/

I will write it referring to Docker-compose of the above URL.

The points are the following 4 points. -Portainer only supports docker-compose of version2, so use version2. -Since the x64 OS was installed last time, Image uses arm64v8. -NextCloud and MariaDB use the same network __ in __bridge mode __. -Set PUID and PGID correctly. -Create a database name and a user who references the database.

Basically, it is okay if the above is satisfied. Please refer to the Docker Hub page and set the detailed Config settings to your liking.

You can set the folder to be bound with volumes as you like, but this time it is bound to the shared folder set with Openmediavault below. There is also a problem with the capacity of the Raspberry Pi itself, so specify a storage directory with sufficient capacity.

It is not necessary if docker-comose is set to database, the user who refers to the database, but if it is not set, log in to Mariadb of Docker to create the database and its database. Create a user to browse for.

docker-compose.yml


version: '2'

services:
  nextclouddb:
    image: linuxserver/mariadb:arm64v8-latest #Use arm64v8
    container_name: nextclouddb
    restart: always
    networks:
      - my-net #Uses the same network as nextcloud
    volumes:
      - /srv/dev-disk-by-label-App/AppData/nextclouddb:/config #Bind Config to common folder (external storage)
    ports:
      - "3306:3306/tcp"
    environment:
      PUID: 1000 #Use UID from id command
      PGID: 1000 #Use GID from id command
      TZ: Asia/Tokyo #Set according to your environment
      MYSQL_DATABASE: nextclouddb #Database name
      MYSQL_USER: raspberrypi #MYSQL_Username that references DATABASE
      MYSQL_PASSWORD: password #MYSQL_USER password
      MYSQL_ROOT_PASSWORD: openmediavault #Administrator password

  nextcloud:
    image: linuxserver/nextcloud:arm64v8-latest #Use arm64v8
    restart: always
    container_name: nextcloud
    networks:
      - my-net #Uses the same network as nextclouddb
    volumes:
      - /srv/dev-disk-by-label-App/AppData/nextcloud:/config #Bind Config to common folder (external storage)
      - /srv/dev-disk-by-label-Media/nextcloud:/data #Bind the directory for cloud storage data to a common folder (external storage)
    ports:
      - "8080:80/tcp" #80 port is used by Openmediavualt, so specify another port
      - "444:443/tcp" #443 Port may also be used by others, so specify another port
    environment:
      PUID: 1000 #Use UID from id command
      PGID: 1000 #Use GID from id command
      TZ: Asia/Tokyo #Set according to your environment
    depends_on:
      - nextclouddb #Start nextcloud after nextclouddb starts
      
networks:
  my-net:
    driver: bridge #Create a network in bridge mode

Installation

Log in to the previously installed Portainer and set up from Stacks in the left pane. Open Add Stack.

スクリーンショット 2020-12-20 090516.png

Set Name Paste the docker-compose into the web editor.

スクリーンショット 2020-12-20 090622.png

Press Deploy the stack to deploy.

スクリーンショット 2020-12-20 090831.png

If deployed correctly, the Container will be added. スクリーンショット 2020-12-20 091024.png

You can see the list of Contaiers from Containers in the left pane. スクリーンショット 2020-12-20 081858.png

Initial setting

Access NextCloud from your browser. Please connect with https. Since I set the https port with 444 with docker-compose, please connect with 444 when specifying the port.

https://{IP address or Host name}:444

Since the SSL certificate is not set, you will be careful when accessing it, but please proceed without worrying about it. スクリーンショット 2020-12-20 092957.png

After connecting to NextCloud, please set the following 3 points from the initial setting screen. · Administrator account and password Please enter what you like.

・ Data folder Please specify /data. If you want to change the directory of /data, bind /data to any directory from volumes of Docker-compose.

・ Database Select MySQL/MariaDB. From the top, specify the account name, password name, database name, and database host name. Use the account name, password name, and database name set in docker-compose. For the database host name, use the IP address of the Raspberry Pi itself.

スクリーンショット 2020-12-20 093442.png

When you're done, press __ to complete the setup __. If you get an error if the account already exists, you can set the account again after the initial settings are completed, so please specify a different account name for the time being.

スクリーンショット 2020-12-20 094044.png

Please wait for a while until NextCloud completes the initialization. It takes about 5 to 15 minutes.

It may become 504 Gateway Time-out on the way, but it is okay because the processing is progressing internally. Please reload properly. When completed, the following screen will appear. When the login screen appears, log in using the account name and password set in the initial settings.

スクリーンショット 2020-12-20 094641.png

After logging in, the dashboard will be displayed. Select a folder from the tab on the upper left. スクリーンショット 2020-12-20 095330.png

I was able to access the storage. スクリーンショット 2020-12-20 095428.png

External storage linkage settings

Set the NAS shared folder built with Openmediavault so that it can be used with NextCloud. Please log in with an administrator account.

Select an app from the account icon in the upper right. スクリーンショット 2020-12-20 101515.png

Search for External storage support in the list and enable it. スクリーンショット 2020-12-20 102142.png

When the plugin is enabled, the item External storage will be added to the administrator item on the setting screen. From Add Storage, select SMB/CIFS. The detailed settings will appear, so set the folder name.

In the advanced settings, set the shared folder set in Building NAS with Openmediavault. For authentication, specify the user name and password, and specify the account that has the access authority of the shared folder set in Openmediavault. After setting everything, click the check button on the far right. If the connection is successful, a green checkmark will appear on the left.

Finally, check __ Allow users to connect to external storage __.

スクリーンショット 2020-12-20 104854.png

If the external storage is displayed in the folder list, it is successful. The icon looks like a shortcut, so please refer to it. スクリーンショット 2020-12-20 105042.png

Now you can use the data folder shared on the NAS from the cloud storage. This completes the cloud storage settings.

Streaming server

NextCloud also has a simple streaming function, but I will try to introduce a proper streaming server. This time, we will use Plex for the streaming server.

Installation

Get Plex's Docker-compose from Docker Hub. https://hub.docker.com/r/linuxserver/plex

I will write it referring to Docker-compose of the above URL.

The points are the following three points. -Portainer only supports docker-compose of version2, so use version2. -Since the x64 OS was installed last time, Image uses arm64v8. -Bind the storage with the files you want to stream with Volumes

Basically, it is okay if the above is satisfied. Please refer to the Docker Hub page and set the detailed Config settings to your liking. If the files you want to stream are in multiple storages, bind them with any directory name.

docker-compse.yml


version: '2'

services:
  plex:
    image: linuxserver/plex:arm64v8-latest
    container_name: plex    
    restart: always
    network_mode: host
    volumes:
      - /srv/dev-disk-by-label-App/AppData/plex:/config
      - /srv/dev-disk-by-label-Movie1/TV:/tv
      - /srv/dev-disk-by-label-Movie1:/movies
      - /srv/dev-disk-by-label-Movie2:/movies2
    ports:
      - "32400/tcp"
    environment:
      PUID: 1000
      PGID: 1000
      VERSION: latest

Add the above docker-compose to the Portainer Stack and deploy Container. (Refer to the introduction of NextCloud)

Initial setting

Access Plex from your browser. The URL of the Web-UI is as follows.

http://{HostName}:32400/web/index.html

When you access it, the login screen will appear, so please log in. If you have not registered an account, please do so.

スクリーンショット 2020-12-20 111432.png

If you log in successfully, the following screen will appear. スクリーンショット 2020-12-20 111615.png

Add library

Select the account menu from the account icon in the upper right. Select Manage → Library from the left pane, and from the Settings screen, select the Add Library button. Then select the library type. Then add a folder. Select the View Media Folder button and specify the folder containing the files you want to stream from under the Docker-compse Volumes bound folder.

When you're done, choose Add to Library.

スクリーンショット 2020-12-20 112343.png

Remote access settings

You can access Plex from the outside by enabling remote access on the Account → Settings → Remote Access screen. All you have to do is press Enable Remote Access.

スクリーンショット 2020-12-20 112636.png

If you want to set your own domain, leave remote access disabled. Set up your custom domain from Account → Settings → Network.

This completes the Plex settings.

at the end

Cloud storage is very convenient because you can use the NAS even when you are away from home by setting the domain and exposing the server to the outside. You can build and play various other servers using Docker, so please refer to it when you are unsure about how to use Raspberry Pi.

Recommended Posts

Play down with Raspberry PI4 as a server. Part 2
First aid as the server goes down with ffi-1.13.1
Minecraft server on Raspberry Pi 4
Write a Reactive server with Micronaut
Launch a stub server with WireMock
Server processing with Java (Introduction part.1)
Raspberry Pi Zero with Ubuntu-style Yocto-gcc with libusb
Find Raspberry Pi from Android with mDNS
Extract a part of a string with Ruby
Use FacesContext as a Mock with PowerMockito
Launched Redmine with Docker on Raspberry Pi 3
raspberry pi 4: Both Raspberry Pi OS and ubuntu boot with just a USB hard disk
Access with Selenium as a countermeasure for navigator.webdriver
Radiko recording server on Raspberry Pi 4 (Docker unused)
I couldn't install docker with raspberry pi2 b +.
Create a web api server with spring boot
Set up a CentOS virtual server with Vagrant
Build Amazon Alexa cheaply with Raspberry Pi 3B + Bluetooth speaker (1. Make a sound first)