SWY's technical notes

Relevant mostly to OS X admins

Providing Snipe-IT via Docker

The goal of this post is to walk through all the steps needed to take a stranger to Docker from ground zero to a working install of Snipe-IT asset manager in a Docker container, linked to a mysql Docker container, storing data on the host volume, where the host is a Synology NAS.  We’ll start with a presumption that the reader knows why Docker exists and what containers are, but doesn’t have a familiarity with how to make Docker work for them.

My workplace needed a better (read: any) asset tracking system, and the venerable Snipe-IT came across my radar as a suitable choice to explore for multiple reasons:

  1. It’s FOSS
  2. There’s a Docker instance, and I wish to up my Docker game
  3. I found other macadmins who use it
  4. @snipeyhead and @uberbrady are smart devs
  5. The online demo didn’t invoke rage, it felt like something we could use.

Unfortunately, like many online docs, Snipe-IT’s documentation makes some presumptions that the reader has a working familiarity with making containers, linking them, and knowing why they would want to store data on the host filesystem vs a container.  When you’re taking your first walk down this road, the path is not always obvious: I hope to illustrate it with what I learned.

When we start with Snipe-IT’s Docker docs, it starts with the basic: “pull our container from Docker Hub”.  This is definitely what you want.  But not where you want to start: this is a cart in front of a horse.  Before we’re ready for a Snipe-IT container, we need to prepare a mysql container.  But before that, let’s get our Synology ready to do awesome Docker stuff.

To do that, log into the DSM web interface on your Synology, click the Main Menu, and head to the Package Center:

Screen Shot 2016-03-03 at 11.51.53 AM

Installing Docker is a one click event, and is now available from the Main Menu.  Start it up.

Synology’s “Docker Registry” is the desired path to get a pre-built container.  We’ll use the registry search tool to find mysql.  It’s the ribbon-wearing “Official Image” that you wish to download: you can select the version via the “Choose Tag” request that comes after clicking the [download]  button:

Screen Shot 2016-03-03 at 12.12.29 PM

mysql:5.6.29 should now be an option under the Image tab.  We are selecting 5.6.29 per the Snipe-it documentation guidelines regarding 5.7 defaulting to strict-mode, and skipping the requirement to disable strict-mode.

Before we get this image running in a container, we’re at a decision point.  Docker images are designed to be non-persistent.  This aspect is great for updating to the latest image, but “non-persistent” is not a good feature in your asset tracking software database.  There are 2 options for getting the needed persistence:

  • Make another “data-only” container.  Pros: containers are easy to relocate. Cons: you need backups. You’re going to need yet another container to perform backups and restores.
  • Map a path from the mysql container out to the local storage. Pros: can use Synology built-in tools to back this data up. Cons: less easy to relocate… but not all that hard.  Still, you’re not fully conforming to the “container all the things!” viewpoint.  Like most decisions in life, neither is purely right or wrong.

I don’t intend to be shipping these containers around at all, and expect that once established, my asset tracking software will stay where it is for the functional life of the NAS.  So for my needs, I’m going with host-based storage.

To start up our Dockerized instance of mysql, Launch that image from the Launch button. The naming is arbitrary (snipe-mysql is logical), and no changes are needed to the port settings: the default of Local as auto mapped to 3306 is appropriate.

Step 2 is all optional.  I haven’t found a need to limit CPU use to make sure it’s a well behaved neighbor to other services, it’s a pretty low-impact service.

On the summary page, click Advanced Settings.  Here’s where we can set more options, such as where to store data.  From volume choose Add Folder, I put mine in the docker directory, and called it snipe-it_mysql.  With this mounted at /var/lib/mysql, mysql data will now be written out to the host storage instead of being put in the container.  Uncheck Read-Only: we better be able to write here.Screen Shot 2016-03-03 at 1.28.32 PM

Links will not be needed: the Snipe-IT container will link TO this container.  If we’d chosen to go with a data storage container, we’d link to it here.

Environment is where we put the rest of the commands.  These are taken from the Snipe-IT documentationScreen Shot 2016-03-03 at 1.16.58 PM(Substituting your own password values is encouraged.)

Click OK and start up the container.  By clicking Details, you should be able to see the one process running, and consult the log.  If all has worked as intended, your log will end with mysqld: ready for connections, and under File Station/docker/snipe-it_mysql, you’ll see some newly created data: the database that containerized mysql is reading and writing.

So it’s time to connect something to it. Back to the Docker registry to download snipe/snipe-it.Screen Shot 2016-03-03 at 1.36.04 PM

 

Start it up from the wizard under Image.  Port 80 is already in use on the NAS, so we can direct a different port into 80 in the container.Screen Shot 2016-03-03 at 1.44.21 PM

Again head to advanced, and link the container to snipe-mysql.  Keep the Alias named mysql:
Screen Shot 2016-03-07 at 1.34.07 PM

The environment variables are from the SnipeIT documentation, moved from the .env file to the Environment Variables section:  If you don’t list SERVER_URL with port 8088, then the dashboard link will fail.  There’s no rule that you have to use 8088, it can be any high port that appeals to you- it just has to match the Local Port value back on step 1 of this section.
Screen Shot 2016-03-07 at 12.43.04 PM

After starting up the snipeit container, I found that when I pointed the browser at the SnipeIT instance, I got this:

Screen Shot 2016-03-03 at 3.06.24 PM

Turns out, that’s expected.  As we read the fine manual, we see that we’re supposed to execute docker exec -i -t snipeit php artisan app:install in our container to get things started.  At first, I thought I’d get away with that in the “Execution Command” field of the window 2 pics above.  No, it’s interactive: it supplies questions to be answered by a human .  This step requires interacting in the Docker container.  To do that:

  1. SSH into the Synology as a local account with admin abilities. sudo -i to become root, authenticating with the local administrator’s password.
  2. Execute docker exec -i -t snipeit php artisan app:install .  This sends the command “php artisan app:install” to the docker container, and drops the user into the container to interact. This script sets up the first user account: use the username and pass defined in the SQL container’s MYSQL_USER and MYSQL_PASSWORD environment variables, and soon after a number of tables are logged as “migrated”, one can point their browser to the SERVER_URL above to start exploring the new web service on the NAS.

With that, you should have a working Snipe-IT install.  Because this project is frequently updated, you’ll periodically want to grab the current release of SnipeIT from Docker hub, to get the latest fixes and enhancements.  To do so:

  1. Head into your Synology’s Docker management interface, and stop the SnipeIT container, then the Snipe-mysql container.
  2. Go to the Registry tab, and search for snipe-it.  Double-click the same official snipe/snipe-it container you used before.  This will update your container to the latest release (equivalent of a ‘docker pull’ command).  Once updated, start the SQL container first, then the SnipeIT, and you’re current.  Unfortunately, via the GUI, this is an obscure process: it lacks feedback if anything is going on.  If you want to see what’s going on, SSH to the Syno and sudo -i as documented above, and run docker pull snipe/snipe-it.
  3. Start up your updated Docker instance just like before.  While things might vary on what the requirements are on future updates, you should expect to need to do some database migrating to match updates.  This is probably easiest if you gain shell access to the Docker instance: docker exec -i -t snipeit /bin/bash 
    1. Execute only the php artisan commands documented in the Snipe-IT upgrade documentation– the Docker container has handled the composer install for you
      php artisan migrate
      php artisan config:clear
      php artisan config:cache

If you’re going to open this service to the WAN, you’ll naturally want to require SSL on it, which is not covered here. If you’re standing up instances of FOSS software via Docker on a NAS, I’m giving you credit for knowing why that’s important.

Advertisements

12 responses to “Providing Snipe-IT via Docker

  1. Synology User December 15, 2016 at 8:16 am

    Thank you! This is an excellent step by step tutorial. Many small and medium companies could use this. Would you be so kind and provide addition as how to set this up with SSL (including getting a certificate). Thank you!

  2. Yusuf Frosh February 10, 2017 at 5:41 pm

    got following error after I the last step

    docker exec -i -t snipeit php artisan app:install

    [Illuminate\Database\QueryException]
    SQLSTATE[01000]: Warning: 1265 Data truncated for column ‘asset_maintenance
    _type’ at row 1 (SQL: insert into `asset_maintenances` (`asset_id`, `asset_
    maintenance_type`, `cost`, `created_at`, `is_warranty`, `start_date`, `supp
    lier_id`, `title`, `updated_at`) values (1, Maintenance, 200.99, 2017-01-18
    23:38:20, 0, 2017-01-18 23:38:20, 1, Test Maintenance, 2017-01-18 23:38:20
    ))

    [PDOException]
    SQLSTATE[01000]: Warning: 1265 Data truncated for column ‘asset_maintenance
    _type’ at row 1

  3. Yusuf Frosh February 10, 2017 at 5:42 pm

    your help will be greatly appreciated

    • swy March 7, 2017 at 5:08 pm

      I can’t say I’ve had to troubleshoot that. My first reaction to that is to wonder if you have the database container properly associated. This might be the install script attempting to configure the database, and you’re failing at row 1 because something is amiss with the DB connection.

  4. jadzla April 18, 2017 at 4:40 pm

    Hi, love the instructions however I am stumped at docker exec -i -t snipeit php artisan app:install as I get the following:
    Error response from daemon: Container 5216dd93e6f3d3172bbc033b8a29de7e79aeb0370d69c9506143a0d96260a54d is not running

    My instance of Snipe-IT is constantly restarting with the log telling me it needs the $APP_key but I can’t see where the .env is to enter it. Any help would be appreciated 🙂

  5. Jason June 21, 2017 at 7:30 am

    Thank you SWY for thi!. I’m actually a complete NOOB to this stuff but proud of myself for getting this far. I have a Synology DS916+ running DSM6. Docker is installed and snipe-mysql (v5.6.29) and snipeit containers are running within it.

    I followed your instructions and here are the settings for the containers ….

    snipe-mysql container
    file/folder – /docker/snipt-it_mysql
    mount path – /var/lib/mysql
    port settings – Auto 3306 TCP
    No links
    Environment variables are set for MYSQL_USER, PASSWORD, DATABASE and ROOT_PASSWORD
    There was a Network tab that defaulted to bridge, but it’s no longer available once the container is created.

    snipeit container
    No volume set
    port settings 8088 80 TCP
    links snipe-mysql mysql
    environment – APP_KEY, SNIPEIT_TIMEZONE, SNIPE_LOCALE AND SERVER_URL set
    SERVER_URL is set to http://192.168.0.93:8088

    When I put that URL in, I get
    Whoops, looks like something went wrong.

    Any thoughts on what I’m doing wrong?

    • swy June 21, 2017 at 10:55 am

      Did you SSH into the synology, and have it run the “docker exec -i -t snipeit php artisan app:install” as documented above? Your experience is consistent with not doing that setup. The good news is that you have the SnipeIT service up and serving back an error page, so that’s one box of “things that need to happen” checked.

      • Jason June 21, 2017 at 2:52 pm

        Thank you for replying SWY. When I do that, it gives me a big red box in Terminal. Inside that box is ..

        [Symfony\Component\Console\Exception\CommandNotFoundException]
        Command “app:install” is not defined.
        Did you mean one of these?
        migrate:install
        app:name

        also, I am logged in as admin but had to put sudo before the line you reference

      • AN July 4, 2017 at 9:16 am

        Hi, can you please advise me, i have the same problem

        [Symfony\Component\Console\Exception\CommandNotFoundException]
        Command “app:install” is not defined.
        Did you mean one of these?
        migrate:install
        app:name

      • AN July 4, 2017 at 10:30 am

        Nevermind, run this with snipeit ver2.1 and this should work. there is no app:install in ver 3.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: