Note that there's a lot of steps to this, but individually none are particularly difficult... I'm not a linux or bsd expert by any means, in fact I'd consider myself a complete amateur. I just pieced this all together from guides I read online, none of this is really my own, I'm just compiling it all in one place. I'm a newb myself so I wrote this as newb-friendly as possible... not to insult anyone's intelligence, just to reach the largest audience possible.
That said, docker for freenas has been getting a lot of attention since corral, and while I never migrated to corral, everyone seemed to rave about docker so I really wanted to give it a shot. It's now possible on freenas 11.0, thanks to native VM support. So here i'll explain step-by-step how I got an emby docker container running on ubuntu server VM in freenas. At the end you'll have emby server running in a docker container on a Ubuntu Server VM, with everything set to auto-start on reboot.
Set up Docker for Ubuntu Server
Note: I installed this on an Ubuntu Server 16.04 VM directly from the Freenas 11 GUI.
- freenas 11.0-U2 (may work on other 11.0 versions but it's confirmed working on this version for me)
- Ubuntu Server 16.04 ISO x64
- vnc viewer
- (optional but highly recommended) - dedicated ssh app - i like secureCRT
First Step - Create the Ubuntu VM
Inside the freenas GUI:
- Go to VM tab, and create a new VM. Create VM name, and give it a good amount of resources, since this will be your container manager. Based on the specs of my server (xeon 1220v3 w/ 32GB RAM), I gave my VM 4 CPUs and 12GB of RAM.
- Once VM is created, before you start it, go to devices tab, add CDROM, and point it to Ubuntu Server 16.04 iso image (it's free, just grab it from wherever)
- Also add a disk, must have zvol to tie to. If no zvol, create a zvol with sufficient size. Mine was 80GB. I won't show how to set up a zvol here, but just search for it, it's a simple process
Now you can start the VM and connect initially via vnc viewer to the port specified on the VM details. It should boot to the ubuntu cdrom and start the installation process.
Install Ubuntu with basic settings. No GUI, no extra features. Just keep it bare bones to keep it lightweight as possible. It will come up with an option to use UEFI boot. Choose that option as that will allow you to auto-start the VM via the freenas GUI.
UEFI Boot Fix
One annoying thing is that the freenas VM system will not boot to uefi automatically. There's an extra step you need to follow to fix this. https://forums.freen...ing-uefi.54039/
Summarizing steps from that guide, if you have shutdown your VM already and try to reboot it (which was my case), it will not automatically start the VM. Instead it will boot to shell. To eliminate this - Just type exit at the shell prompt, and in the EFI menu system navigate to "Boot Maintenance Manager" and then select "Boot from file" to locate and select your grubx64.efi file.
Once the VM is started, log in as root.
As root, cd to the
directory of your VM in order to create the new BOOT directory and copy the existing grubx64.efi to /EFI/BOOT/bootx64.efi.
mkdir /boot/efi/EFI/BOOT cp /boot/efi/EFI/ubuntu/grubx64.efi /boot/efi/EFI/BOOT mv /boot/efi/EFI/BOOT/grubx64.efi /boot/efi/EFI/BOOT/bootx64.efi
The end result should look like this, using Ubuntu as an example:
root@ubuntu-vm:/boot/efi# tree -L 3 . . └── EFI ├── BOOT │ └── bootx64.efi └── ubuntu ├── fbx64.efi ├── grub.cfg ├── grubx64.efi ├── mmx64.efi └── shimx64.efi 3 directories, 6 files root@ubuntu-vm:/boot/efi#
The file bootx64.efi is a copy of the grubx64.efi in your VM.
NB: If grubx64.efi gets updated you will need to re-create bootx64.efi
Restart the VM from the freenas GUI, and see if it boots directly to VM.
Now your ubuntu VM should be up and running, and it will auto-start on reboots.
As soon as I got Ubuntu up and running, I made sure to enable ssh access.
Set Up SSH Access (Optional but Reccomended)
sudo apt-get install openssh-server
Now you can access the VM via ssh (I like secureCRT) instead of relying on vnc viewer.
Also, make sure to mount NAS folder to give NAS access to your VM -
- Install cifs-utils
apt-get install cifs-utils
Create the directory and mount the device using the following commands (I named my mount point "freenas". Name it whatever you want).
sudo mkdir /mnt/freenas
Now mount the device using cifs
mount -t cifs //192.168.0.155/nas -o username=anonymous,password=,rw,nounix,iocharset=utf8,file_mode=0644,dir_mode=0755 /mnt/freenas
Change the ip address and folders to match the path to your particular NAS setup. My nas is setup for anonymous access internally. You might want to be more secure if you have multiple users, so change those settings as you see fit.
sudo df -Th /mnt/freenas/
Test the directory and make sure your VM now has access to your freenas files. Once tested, you'll wan to make permanent so it persists on reboot.
edit /etc/fstab and append -
//192.168.0.155/nas /mnt/freenas cifs username=anonymous,password=,rw,nounix,iocharset=utf8,file_mode=0755,dir_mode=0755
Again, change the path and options as it matches your particular setup. Test that all this is working by stopping your VM, restarting it, and making sure that your NAS is still accessible via your mount point.
Now you're ready to actually install docker.Installing Docker
taken from here
The Docker installation package available in the official Ubuntu 16.04 repository may not be the latest version. To get the latest and greatest version, install Docker from the official Docker repository. This section shows you how to do just that.
First, add the GPG key for the official Docker repository to the system:
curl -fsSLhttps://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add the Docker repository to APT sources:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu/ $(lsb_release -cs) stable"
Next, update the package database with the Docker packages from the newly added repo:
sudo apt-get update
Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:
apt-cache policy docker-ce
You should see output similar to the follow:
Output of apt-cache policy docker-ce
docker-ce: Installed: (none) Candidate: 17.03.1~ce-0~ubuntu-xenial Version table: 17.03.1~ce-0~ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages 17.03.0~ce-0~ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
Notice that docker-ce is not installed, but the candidate for installation is from the Docker repository for Ubuntu 16.04. The docker-ce version number might be different.
Finally, install Docker:
sudo apt-get install -y docker-ce
Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it's running:
sudo systemctl status docker
The output should be similar to the following, showing that the service is active and running:
● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2016-05-01 06:53:52 CDT; 1 weeks 3 days ago Docs: https://docs.docker.com Main PID: 749 (docker)
Installing Docker now gives you not just the Docker service (daemon) but also the docker command line utility, or the Docker client. All we need for now.
Install and Set Up Portainer (Optional but recommended)
taken from here
sudo docker pull portainer/portainer
Let us check whether the Portainer image has been pulled or not.
sudo docker images
portainer/portainer latest ec91653336d4 7 days ago 9.132 MB
As you see in the above output, Portainer image size is less than 10 MB, which is very small so that I won’t consume more RAM and Hdd space.
We have now Portainer in our local Ubuntu system. Let us start the container using command (this command allows portainer to be persistent on restart):
docker run -d -p 9000:9000 --restart always --name portainer -v /opt/portainer-data:/data -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
Now, Portainer is running! Let us go ahead and access the Portainer UI. To do so, open your wbe browser and point it to – http://localhost:900..._Address:9000/.You will be presented with a screen like below that asks to setup a password for the admin user.
Enter the password twice and hit Validate button to create the admin user password.
Finally - Add Emby Docker Image
Taken from here -
We recommend you install directly from the Docker Hub. Before starting the install procedure please verify the following prerequisites are fulfilled:
- ensure the user running installation command can run docker
Start the installation by issuing the following command from within a terminal (restart always & define port will make persistent on restart):
docker run -it --rm -v /usr/local/bin:/target emby/embyserver instlSet Up Emby
run the emby-server command
It will ask you to add volume locations.
Use the mounted freenas directory to give access to NAS (or whatever folder you set up to mount with your NAS)
That's it for the cli portion of emby set-up. Just ctrl+D to exit.
Now, go into portainer, check images. You should see emby server. Click the link hyperlink. Look for the expose detail. Use one of the available tcp ports. For me, it was tcp port 8096.
Now just enter the url of the docker VM with the correct port number:
That should go directly to the emby set up screen. You're done!
But one last thing before we finish...Enable Systemd Emby (Optional - allows emby-server to auto-start with docker VM)
By deafult, containers don't auto-start on reboot. If you want this to happen, which is extremely convenient, you need to give it an appropriate run command. There's several ways to do this with docker, but in Ubuntu, systemd seems to be the recommended way to go. This is probably the most complex part of this tutorial, since the contents of your custom unit will vary depending on your personal setup. Use mine as a general guide and tweak as needed.
On some emby docker tutorials, there are one-line commands that get emby-server to get included in systemd, but I couldn't get any of them to work for me for some reason, so I had to set up my own systemd service to make it work.
I installed an app called systemd-docker for docker auto starts. Found it in a suggestion in the emby docker thread and it worked for me.
apt-get install systemd-docker
Then create the unit emby-docker.service file that goes into /etc/systemd/system/
things to note on the switches used in the "ExecStart" section -
-v = volume
-e = environment variable
A good tip is to go into Portainer, look at the emby-server container you set up earlier, and look at the details of the container to get the settings of your ENV and volume sections. Then use the switches as shown in my example to configure your unit to match your personal setup. Some other tips -
- For my set-up, my volume referred to my mount point of my NAS. Change that to match what yours is.
- I run my emby container as root user. I have no problem with this. If you want to run it as some other user, you need to change the user as needed
- TZ = timezone. It's important to have that match your local timezone. Look up linux timezones and find one that matches yours.
The rest I think you can keep the same and it shouldn't cause you many issues, but of course depends on your set-up. This took me a while to figure out and get right, and there may very well be easier ways to do this.
Here's my sample emby-docker.service file. Make sure to give the file full rw permissions so it can be executed by systemd.
[Unit] Description=Emby-Server Docker After=docker.service Requires=docker.service [Service] ExecStart=/usr/bin/systemd-docker run --rm --name %n --net=host -v /home/root/.emby-server:/config -v /mnt/freenas:/mnt/freenas -e APP_UID=0 -e APP_GID=0 -e APP_USER=root -e EDGE=0 -e UMASK=002 -e TZ='America/New_York' emby/embyserver Restart=always RestartSec=10s Type=notify NotifyAccess=all TimeoutStartSec=120 TimeoutStopSec=15 [Install] WantedBy=multi-user.target
Enable it to make it persistent -
sudo systemctl enable emby-docker
Then start it
sudo systemctl start emby-docker
You should see the container running in portainer in your containers list, and you should be able to access your emby server on the default 8096 port. This time however, the container will always auto-start with your VM.
Edited by Hisma, 13 August 2017 - 08:57 PM.