# Labkey as a docker container

This git project contains everything required to start labkey as a docker container.

## Installation

### Prepare

- Install [`docker`][docker] and [`docker-compose`][dockerCompose]
- create a user `labkey` with `docker` privileges

```bash
sudo adduser labkey
sudo usermod -G docker labkey
```

- clone the software directly into home

```bash
sudo su labkey
cd
git init .
git remote add origin <repository-url>
git pull origin master
```

- run `bin/installLabkey.sh 22.3` to unzip the enclosed LabKey binary code and make appropriate links.
- copy `bin/env.sh.sample` to `bin/env.sh` and set a secret `$PGPASS`, other settings are probably OK, 
  check `$DOCKERCOMPOSE`
- set the same value as `password` in `labkey/labkey.xml` 
  
### Start containers
  
Run `bin/startLabkey.sh`. This will do several things:
   - Download PostgreSQL image and initialize a persistent database at `~/postgresl/data`. 
  - Build a combined tomcat/R image from a recent version of tomcat
  - Copy and link files from home to the server
  - Start the server

### Check the installation
  
In principle, the service should be running at `http://localhost:8443/labkey`. Check output of inidividual 
  components by:
  
```bash
  docker logs config-db-1
  docker logs config-web-1
  docker exec -it config-db-1 bash
  
```

### Add ggplot2 to R

Connect to running instance of labkey:

```bash
docker exec -it config_labkey-web_1 bash
```

Start R:

```bash
R
```

In R, install`ggplot2` with dependencies:

```R
install.packages('ggplot2', repos='http://cran.us.r-project.org', dependencies=TRUE)
```

### Expected errors
  
Errors of the type `500: Unexpected server error` are common and related 
  
[docker]: https://docs.docker.com/engine/install/
[dockerCompose]: https://docs.docker.com/compose/install/