Hisma
Explorer
- Joined
- Mar 23, 2013
- Messages
- 87
I originally wrote this for emby users, but because this is certainly relevant to freenas users, I'll cross-post it here, since once you get docker working, you can use it to set up any container you see fit. I will use emby server as my container of choice though.
Here's the original I wrote -
https://emby.media/community/index....0-u2-running-emby-via-docker-in-an-ubuntu-vm/
And here it is for freenas users to pursue, since I figure this may warrant freenas-specific discussion. This is an alternative to RancherOS for those that may feel uncomfortable going that route. Feel free to suggest any improvements or point out any errors. I also copy-pasted directly from some other content, so if this bothers anyone, let me know and I'll delete it. Not trying to claim others work as my own, again, I just think it's useful to have everything accessible in one place.
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. Also, as 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.
At the end of this guide you'll have emby server running in a docker container on a Ubuntu Server VM, with everything set to auto-start on reboot.
Note: I installed this on an Ubuntu Server 16.04 VM directly from the Freenas 11 GUI.
PreReqs:
Inside the freenas GUI:
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 which is detailed in this forum already. https://forums.freen...ing-uefi.54039/
Summarizing steps from that guide here, 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.
The end result should look like this, using Ubuntu as an example:
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)
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 -
Create the directory and mount the device using the following commands (I named my mount point "freenas". Name it whatever you want).
Now mount the device using cifs
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.
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 -
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
https://www.digitalo...on-ubuntu-16-04
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:
Add the Docker repository to APT sources:
Next, update the package database with the Docker packages from the newly added repo:
Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:
You should see output similar to the follow:
Output of apt-cache policy docker-ce
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:
Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it's running:
The output should be similar to the following, showing that the service is active and running:
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
https://www.ostechni...-manage-docker/
Let us check whether the Portainer image has been pulled or not.
Sample output:
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):
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 -
https://hub.docker.c...dukrbdutjzkjtz/
We recommend you install directly from the Docker Hub. Before starting the install procedure please verify the following prerequisites are fulfilled:
Set 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.
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 -
Here's my sample emby-docker.service file. Make sure to give the file full rw permissions so it can be executed by systemd.
Enable it to make it persistent -
Then start it
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.
Here's the original I wrote -
https://emby.media/community/index....0-u2-running-emby-via-docker-in-an-ubuntu-vm/
And here it is for freenas users to pursue, since I figure this may warrant freenas-specific discussion. This is an alternative to RancherOS for those that may feel uncomfortable going that route. Feel free to suggest any improvements or point out any errors. I also copy-pasted directly from some other content, so if this bothers anyone, let me know and I'll delete it. Not trying to claim others work as my own, again, I just think it's useful to have everything accessible in one place.
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. Also, as 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.
At the end of this guide you'll have emby server running in a docker container on a Ubuntu Server VM, with everything set to auto-start on reboot.
Note: I installed this on an Ubuntu Server 16.04 VM directly from the Freenas 11 GUI.
PreReqs:
- 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 (other versions may work but confirmed working on this version for me)
- vnc viewer
- (optional but highly recommended) - dedicated ssh app - i like secureCRT
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
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 which is detailed in this forum already. https://forums.freen...ing-uefi.54039/
Summarizing steps from that guide here, 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.
Code:
sudo -i
As root, cd to the
Code:
/boot/efi/EFI
directory of your VM in order to create the new BOOT directory and copy the existing grubx64.efi to /EFI/BOOT/bootx64.efi.
Code:
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:
Code:
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)
Code:
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
Code:
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).
Code:
sudo mkdir /mnt/freenas
Now mount the device using cifs
Code:
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.
Code:
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 -
Code:
//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
https://www.digitalo...on-ubuntu-16-04
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:
Code:
curl -fsSLhttps://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add the Docker repository to APT sources:
Code:
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:
Code:
sudo apt-get update
Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:
Code:
apt-cache policy docker-ce
You should see output similar to the follow:
Output of apt-cache policy docker-ce
Code:
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:
Code:
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:
Code:
sudo systemctl status docker
The output should be similar to the following, showing that the service is active and running:
Code:
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
https://www.ostechni...-manage-docker/
Code:
sudo docker pull portainer/portainer
Let us check whether the Portainer image has been pulled or not.
Code:
sudo docker images
Sample output:
Code:
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):
Code:
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 -
https://hub.docker.c...dukrbdutjzkjtz/
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
Code:
docker run -it --rm -v /usr/local/bin:/target emby/embyserver instl
Set Up Emby
run the emby-server command
Code:
emby-server
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)
Code:
/mnt/freenas
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.
Code:
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.
Here's my sample emby-docker.service file. Make sure to give the file full rw permissions so it can be executed by systemd.
Code:
[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 -
Code:
sudo systemctl enable emby-docker
Then start it
Code:
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.