# Step By Step How I Setup My HomeLab Docker Containers

## Installing VirtualBox

1. Download VirtualBox Download
2. Download VirtualBox Extension Pack Download
3. Install VirtualBox, accepting the defaults
4. Install VirtualBox Extension Pack, accepting the defaults
5. Launch VirtualBox if it is not already running

## Creating TurnKey Core VirtualBox VM

1. Download the TurnKey Linux Core .ova Download
2. In VirtualBox, select File > Import Appliance...
3. Click the Browse icon > Navigate to and select the downloaded .ova file
4. Click Next and then Import
5. Make sure the Turnkey Core VM is selected and click Start > Normal
6. Once the VM boots, enter a new root password
7. Select Skip on the TurnKey Backup and Migration screen
8. Select Skip on the System Notifications screen
9. Select Install on the Security Updates screen
10. Note the URLs and IP address for the VM > Press Enter to finish the installation

## Installing Docker

1. Execute the following commands in a terminal:
   # update software repositories
   apt update
   # install necessary packages for https apt calls
   apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
   # add docker GPG key
   curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
   # add docker software repository
   add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
   # install docker
   apt update
   apt install docker-ce docker-ce-cli containerd.io
   # create a docker group
   groupadd docker
   # add the current user to the docker group
   usermod -aG docker $USER

## Running Portainer Docker Container

1. Continue with the following commands in terminal to run Portainer:
   # create a working directory for portainer
   mkdir ~/docker/portainer -p
   # run the portainer docker container
   docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v ~/docker/portainer:/data portainer/portainer-ce
2. Once the Portainer container is downloaded and running, open a web browser and navigate to http://DNSorIP:9000
3. Set an administrator username and password > Click Create user
4. Click the Docker - Manage the local Docker environment option > Click Connect
5. Select Networks from the left navigation menu
6. Click the Add Network button
7. Complete the Create network form as follows:

   Name: container-network
   Subnet: 173.27.0.0/16
   Gateway: 173.27.0.1

8. Click the Create the Network button at the bottom of the page

## Adding Additional Docker Containers From Portainer UI

1. Select Containers from the left navigation menu
2. For each of the containers listed below, click the Add Container button and complete the Create container form with the values given

### Heimdall

Name: heimdall
Image: ghcr.io/linuxserver/heimdall:latest
Ports: 40000 → 80
Volumes: /config → /root/docker/heimdall
Env:
PUID: 1000
PGID: 1000
TZ: America/New_York
Restart Policy: Unless Stopped

### MySQL

Name: MySQL
Image: mysql:latest
Ports: 3306 → 3306
Volumes: /var/lib/mysql → /root/docker/mysql
Env:
MYSQL_ROOT_PASSWORD: password
Restart Policy: Unless Stopped

### phpMyAdmin

Name: phpMyAdmin
Image: phpmyadmin:latest
Ports: 40001 → 80
Env:
PMA_HOST: MySQL
Restart Policy: Unless Stopped

### PostgreSQL

Name: postgres
Image: postgres:latest
Ports: 5432 → 5432
Volumes: /var/lib/postgresql/data → /root/docker/postgresql/data
Env:
POSTGRES_PASSWORD: postgres
Restart Policy: Unless Stopped

### phpPGAdmin

Name: phpPGAdmin
Image: bitnami/phppgadmin:latest
Ports: 40004 → 8080
Env:
POSTGRESQL_HOST: postgresql
Restart Policy: Unless Stopped

### Watchtower

Name: watchtower
Image: containrrr/watchtower:latest
Volumes: /var/run/docker.sock → /var/run/docker.sock
Env:
WATCHTOWER_NOTIFICATION_EMAIL_FROM: watchtower@i12bretro.local
WATCHTOWER_NOTIFICATION_EMAIL_TO: sysadmin@i12bretro.local
WATCHTOWER_NOTIFICATION_EMAIL_SERVER: smtp.i12bretro.local
WATCHTOWER_NOTIFICATIONS: email
WATCHTOWER_NO_STARTUP_MESSAGE: true
Restart Policy: Unless Stopped

### Apache HTTPD

Name: httpd
Image: httpd:alpine
Ports: 80 → 80
Volumes: /usr/local/apache2/conf → /root/docker/apache2/conf
Restart Policy: Unless Stopped

### Pi-Hole

Name: pihole
Image: pihole/pihole:latest
Ports: 53 → 53, 53 → 53 UDP, 67 → 67 UDP, 40002 → 80
Volumes:
/etc/pihole/ → /root/docker/pihole/etc/
/etc/dnsmasq.d/ → /root/docker/pihole/dnsmasq.d/
Env:
TZ: America/New_York
WEBPASSWORD: password
Restart Policy: Unless Stopped

### guacd

Name: guacd
Image: guacamole/guacd:latest
Restart Policy: Unless Stopped

## Completing Network Setup

1. Select Containers from the left navigation menu
2. Click the MySQL container
3. Scroll down to the Networks section > Select container-network from the dropdown > Click Join Network
4. Do the same for the phpMyAdmin, Postgres, phpPGAdmin, guacd and Guacamole containers

## Creating Apache HTTPD Reverse Proxy

1. Run the following command in terminal on the Docker host:
   # copy the httpd.conf from container to host
   docker cp httpd:/usr/local/apache2/ /root/docker/apache2
   # edit httpd.conf
   nano ~/docker/apache2/conf/httpd.conf
2. Uncomment the following module lines by removing the #

   LoadModule proxy_module modules/mod_proxy.so
   LoadModule proxy_connect_module modules/mod_proxy_connect.so
   LoadModule proxy_http_module modules/mod_proxy_http.so
   LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so

3. Paste the following at the bottom of the file

   ProxyPreserveHost On

   <Location /guacamole/>
   Order allow,deny
   Allow from all
   ProxyPass http://192.168.0.75:40003/guacamole/ flushpackets=on
   ProxyPassReverse http://192.168.0.75:40003/guacamole/
   </Location>

   <Location /guacamole/websocket-tunnel>
   Order allow,deny
   Allow from all
   ProxyPass ws://192.168.0.75:40003/guacamole/websocket-tunnel
   ProxyPassReverse ws://192.168.0.75:40003/guacamole/websocket-tunnel
   </Location>

   <Location /phpmyadmin/>
   Order allow,deny
   Allow from all
   ProxyPass http://192.168.0.75:40001/
   ProxyPassReverse http://192.168.0.75:40001/
   </Location>

   <Location /phppgadmin/>
   Order allow,deny
   Allow from all
   ProxyPass http://192.168.0.75:40004/
   ProxyPassReverse http://192.168.0.75:40004/
   </Location>

   <Location /pihole/>
   Order allow,deny
   Allow from all
   ProxyPass http://192.168.0.75:40002/admin/
   ProxyPassReverse http://192.168.0.75:40002/admin/
   </Location>

   <Location /portainer/>
   Order allow,deny
   Allow from all
   ProxyPass http://192.168.0.75:9000/
   ProxyPassReverse http://192.168.0.75:9000/
   </Location>

   ProxyPass / http://192.168.0.75:40000/
   ProxyPassReverse / http://192.168.0.75:40000/

4. Press CTRL+O, Enter, CTRL+X to write the changes to httpd.conf
5. Back in the Portainer UI, select Containers from the left navigation menu
6. Check the box next to httpd > Click the Restart button