Storage

TrueNAS Docker Compose with Scale Apps and Truecharts

TrueNAS Docker Compose with Scale Apps and Truecharts. A look at TrueNAS Docker and Docker Compose and using Truecharts for apps

One of the cool features of TrueNAS Scale is the ability to run Docker containers on your system. It means your TrueNAS system can serve as your Docker host and provide storage for your environment, including your home lab or production environments. Let’s look at this feature and see how it can run containerized applications easily.

Introduction to TrueNAS SCALE

TrueNAS SCALE is an open-source, Linux-based storage platform that provides home users and enterprises with powerful features and advanced functionality. It is designed to offer a comprehensive and scalable solution, building on the solid foundation of TrueNAS CORE.

With its flexible containerization options and seamless integration with Docker, TrueNAS SCALE allows users to quickly deploy various applications and other apps.

Setting up a TrueNAS SCALE System

Hardware Requirements and VM Setup

You’ll need a compatible hardware setup or a virtual machine (VM) running Ubuntu. Ensure your VM or hardware meets the minimum system requirements for TrueNAS SCALE, including adequate storage, RAM, and CPU resources.

For optimal performance, it is recommended to use dedicated hardware or a VM with NVIDIA passthrough capabilities.

Installing TrueNAS SCALE

  1. Download the latest version of TrueNAS SCALE from the official repository.

  2. Create a bootable USB drive using the downloaded ISO file.

  3. Boot your system or VM from the USB drive and follow the on-screen prompts to complete the installation process.

Configuring TrueNAS SCALE Storage

Creating a Storage Pool

Once TrueNAS SCALE is installed, you must create a storage pool to store your Docker containers, datasets, and other files. Access the TrueNAS SCALE web interface and navigate to the “Storage” section. Here, you can create a new pool by clicking “Add” and selecting the desired drives for your pool. It is recommended to use ZFS as the storage driver for optimal performance and data integrity.

Creating a Docker Dataset

After creating a storage pool, you must create a dedicated Docker dataset for your containers. This can be done by navigating to the “Datasets” tab in the “Storage” section and clicking “Add.” Enter a name for the Docker dataset and ensure that the “Enable Docker” checkbox is ticked. This will enable Docker support for the dataset.

Setting up a Boot Pool

A boot pool is necessary to store system settings and ensure smooth booting of your TrueNAS SCALE system. To create a boot pool, navigate to the “Boot” tab in the “Storage” section and click “Add.” Select the appropriate drives and options, then click “Save” to create the boot pool.

Managing App Data with Datasets

Create separate datasets within your storage pool to store and manage data for your Scale Apps. This allows for easy organization and management of app data while ensuring data integrity and protection.

To create a new dataset, navigate to the “Datasets” tab in the “Storage” section of the TrueNAS SCALE web interface and click “Add.” Enter a name for the dataset and configure any necessary settings, such as compression and deduplication.

Once your datasets are created, you can map them to the appropriate Docker containers by specifying the dataset paths in the “volumes” section of your “docker-compose.yml” file.

Migrating from TrueNAS Core to TrueNAS SCALE

If you’re currently using TrueNAS Core and want to migrate to TrueNAS SCALE, you’ll need to follow a few steps to ensure a smooth transition.

  1. Backup your data: Before starting the migration process, it’s crucial to back up all your important data, including your TrueNAS Core configuration, datasets, and app data. You can use the built-in snapshot and replication features in TrueNAS Core to help with this task.

  2. Prepare your hardware: Make sure your hardware meets the requirements for TrueNAS SCALE. This may involve upgrading your system’s RAM, storage drives, or network interfaces.

  3. Install TrueNAS SCALE: Follow the official installation guide to install TrueNAS SCALE on your hardware or virtual machine. This will involve downloading the TrueNAS SCALE installation image, creating a bootable USB drive, and running the installer on your target system.

  4. Import your datasets: After installing TrueNAS SCALE, you must import your datasets from your TrueNAS Core system. This can be done through the TrueNAS SCALE web interface by navigating to the “Storage” section and clicking “Import Pool.”

  5. Migrate app data and settings: Once your datasets have been imported, you’ll need to migrate your app data and settings to the new system. This may involve recreating your Docker containers and adjusting their configurations to match your previous TrueNAS Core setup.

  6. Test your new setup: After migrating your app data and settings, test your new TrueNAS SCALE system to ensure everything functions as expected. This may involve verifying that your apps are accessible, your datasets function correctly, and your system resources are utilized efficiently.

  7. Switch to production use: Once satisfied that your new TrueNAS SCALE system is stable and fully operational, you can use it for your production workloads.

Working with Docker on TrueNAS SCALE (Current releases)

With TrueNAS Scale now, there is no need to install Docker out of the box as it is installed by default when you deploy TrueNAS Scale. The TrueNAS Scale apps functionality allows you to work with Docker containers, and the functionality easil

y is built into the solution without installing Docker, etc.

However, one thing to note. If you want to use Docker Compose, you won’t have this functionality built in with the out-of-the-box functionality. It only includes Docker by default. However, you can add Docker Compose by installing the Truecharts repository. Truecharts can install Docker compose as an “app.

After adding the Truecharts repository, you can find the Docker Compose app.

Install Docker on TrueNAS SCALE without Kubernetes

TrueNAS SCALE implements Docker with Kubernetes. So, in effect, it runs Docker in Docker. You can use a custom (unsupported – use at own risk) script to enable Docker on TrueNAS without Kubernetes:

Enable Docker on TrueNAS SCALE (without kubernetes) (github.com)

You can use the script and run systemctl restart docker elif with the script to implement the solution. Below you can see Docker Compose running in a Docker container in Kubernetes.

Install Docker on TrueNAS Scale (alpha or beta releases)

The following information is for posterity purposes, as you will most likely be using a recent release of TrueNAS SCALE with Docker built into the app.

Installing Docker from the command line

Early TrueNAS SCALE (alpha/beta) versions may have required users to install Docker. To do this, access the TrueNAS SCALE console and run the following command to enable the APT repository for Docker:

sudo apt-get update && sudo apt-get install docker-ce

With Docker installed, you can run Docker container applications.

Configuring Docker Settings

Once Docker is installed, you’ll need to configure its settings. First, create a docker-compose.yml file in the Docker dataset directory by running the following command in the TrueNAS SCALE console:

touch /path/to/docker-dataset/docker-compose.yml

Next, use the YAML format to open the docker-compose.yml file in a text editor and define your desired Docker containers, networks, volumes, and other settings.

Enabling and Starting Docker Daemon

You’ll need to enable and start the Docker daemon to run Docker containers. First, create a docker-daemon.json file in the /etc/docker directory by running the following command in the TrueNAS SCALE console to create the Docker daemon file to configure the Docker executable:

sudo touch /etc/docker/daemon.json

Open the docker-daemon.json file in a text editor and add the following lines to specify the Docker dataset as the default storage location for Docker containers:

{ "data-root": "/path/to/docker-dataset" }

Save the file and exit the text editor. Next, enable the Docker service by running the following command in the TrueNAS SCALE console:

sudo systemctl enable docker

To start the Docker service, run the following command:

sudo systemctl start docker

For restarting docker, you can use the command:

sudo systemctl restart docker

You can verify that the Docker service is enabled and active by running these commands:

sudo systemctl is-enabled docker sudo systemctl is-active docker

Creating an Enable Docker Script

To ensure that Docker starts automatically after each reboot, create an “enable-docker.sh” script in your home directory:

touch ~/enable-docker.sh

Open the “enable-docker.sh” script in a text editor and add the following lines:

#!/bin/bash sudo systemctl enable docker sudo systemctl start docker

Save the file and exit the text editor. Next, make the script executable:

chmod +x ~/enable-docker.sh

Finally, add the script to your system’s startup process by creating a symlink in the “/etc/init.d” directory:

sudo ln -s ~/enable-docker.sh /etc/init.d/enable-docker.sh

Installing Docker Compose

To deploy Scale Apps using Docker containers, you’ll need Docker Compose. Install the Docker Compose executable by running the following command in the TrueNAS SCALE console:

sudo apt-get install docker-compose

Deploying Apps with Docker Compose

With Docker Compose installed you can now deploy your Scale Apps using the “docker-compose.yml” file you created earlier. Open the file in a text editor and define your desired apps using the YAML format. Include any necessary environment variables, ports, and volumes for each app.

To deploy your apps, navigate to the directory containing the “docker-compose.yml” file and run the following command in the TrueNAS SCALE console:

docker-compose up -d

This command will download the specified Docker images, create the necessary Docker containers, and start the containers in the background.

Managing Docker Containers

To view a list of your active Docker containers, run the following command in the TrueNAS SCALE console in legacy versions:

docker ps

You can start, stop, and restart containers using the following commands:

docker start <container_name> docker stop <container_name> docker restart <container_name>

To update your Docker containers, first pull the latest images:

docker-compose pull

Then, recreate the containers and restart them:

docker-compose up -d --force-recreate

Wrapping up

TrueNAS Docker is a great way to run quick and easy applications in your home lab or another environment. Not only does TrueNAS SCALE provide storage, but it also allows you to run applications via Docker and Docker Compose to easily and quickly launch. Remember, even with the new releases of TrueNAS SCALE, Docker Compose is not built-in by default.

You will still need to install the Docker Compose app via Truecharts as shown, or in an unsupported way by manually installing Docker Compose at the OS level which will not be integrated with your TrueNAS SCALE dashboard and apps.

Subscribe to VirtualizationHowto via Email 🔔

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com and has over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, Brandon has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.