# Running Snipe-IT in Docker on Ubuntu Server

## What is Snipe-IT?

Snipe-IT is a Free Open Source (FOSS) project built on Laravel. Snipe-IT was made for IT asset management, to enable IT departments to track who has which laptop, when it was purchased, which software licenses and accessories are available, and so on. - https://snipe-it.readme.io/docs

## Installing Docker

1. Log into the Linux host
2. Run the following commands in a terminal window
   # install prerequisites
   sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y
   # add docker gpg key
   curl -fsSL https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release)/gpg | sudo apt-key add -
   # add docker software repository
   sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release) $(lsb_release -cs) stable"
   # install docker
   sudo apt install docker-ce docker-compose containerd.io -y
   # enable and start docker service
   sudo systemctl enable docker && sudo systemctl start docker
   # add the current user to the docker group
   sudo usermod -aG docker $USER
   # reauthenticate for the new group membership to take effect
   su - $USER

## Running Snipe-IT

1. Continue with the following commands in terminal to setup and run Snipe-IT
   # create working directories
   sudo mkdir ~/docker/snipeit/{config,data} -p && sudo mkdir ~/docker/mariadb -p
   # create snipeit network
   docker network create snipeit
   # download the base configuration
   sudo wget -O ~/docker/snipeit/.env https://raw.githubusercontent.com/snipe/snipe-it/master/.env.example
   # generate an app_key
   docker run --rm snipe/snipe-it
   # edit the .env file
   sudo nano ~/docker/snipeit/.env
2. Scroll through the .env file, making sure to comment out the mysql connection details and change the following fields as needed

   # --------------------------------------------
   # REQUIRED: BASIC APP SETTINGS
   # --------------------------------------------
   APP_ENV=production
   APP_DEBUG=false
   APP_KEY=<%PASTED APP_KEY%>
   APP_URL='http://<%DNSorIP%>:8000'
   APP_TIMEZONE='America/New_York'
   APP_LOCALE=en
   MAX_RESULTS=500

   # --------------------------------------------
   # REQUIRED: UPLOADED FILE STORAGE SETTINGS
   # --------------------------------------------
   PRIVATE_FILESYSTEM_DISK=local
   PUBLIC_FILESYSTEM_DISK=local_public

   # --------------------------------------------
   # REQUIRED: DATABASE SETTINGS
   # --------------------------------------------
   DB_CONNECTION=mysql
   DB_HOST=db
   DB_DATABASE=snipe_it
   DB_USERNAME=snipe_it_rw
   DB_PASSWORD=Snip3-IT!
   DB_PREFIX=null
   # --------------------------------------------
   # REQUIRED: OUTGOING MAIL SERVER SETTINGS
   # --------------------------------------------
   MAIL_DRIVER=smtp
   MAIL_HOST=smtp.i12bretro.local
   MAIL_PORT=25
   MAIL_USERNAME=null
   MAIL_PASSWORD=null
   MAIL_ENCRYPTION=null
   MAIL_FROM_ADDR=snipe-it@i12bretro.local
   MAIL_FROM_NAME='Snipe-IT'
   MAIL_REPLYTO_ADDR=snipe-it@i12bretro.local
   MAIL_REPLYTO_NAME='Snipe-IT'
   MAIL_AUTO_EMBED_METHOD='attachment'

3. Press CTRL+O, Enter, CTRL+X to write the changes to .env
4. Continue with the following commands in terminal
   # set owner of docker directory
   sudo chown "$USER":"$USER" ~/docker -R
   # set permissions on docker directory
   sudo chmod g+rwx "$HOME/docker" -R
   # run the mariadb docker container
   docker run -d --name mariadb --network snipeit --network-alias db -e MYSQL_ROOT_PASSWORD=r00tp@ss -e MYSQL_USER=snipe_it_rw -e MYSQL_PASSWORD=Snip3-IT! -e MYSQL_DATABASE=snipe_it -v ~/docker/mariadb:/var/lib/mysql --restart=unless-stopped mariadb:latest
   # run the snipeit container
   docker run -d --name snipeit -p 8000:80 --network snipeit --env-file=$HOME/docker/snipeit/.env -v ~/docker/snipeit/data:/var/lib/snipeit -v ~/docker/snipeit/config:/config --restart=unless-stopped snipe/snipe-it:v5.1.7

## Snipe-IT Web Installer

1. Open a web browser and navigate to http://DNSorIP:8000
2. Review the Pre-Flight Checks summary > Click the Next: Create Database Tables button
3. Once the database tables are created, Click the Next: Create User button
4. Create a user by inputting a site name, first name, last name, email address, username and password > Click the Next: Save User button
5. Welcome to Snipe-IT running on Docker

Documentation: https://hub.docker.com/r/snipe/snipe-it/