README.md 3.5 KB
Newer Older
Nikita Titov's avatar
Nikita Titov committed
1
# Using LightGBM via Docker
wxchan's avatar
wxchan committed
2

Nikita Titov's avatar
Nikita Titov committed
3
This directory contains `Dockerfile`s to make it easy to build and run LightGBM via [Docker](https://www.docker.com/).
wxchan's avatar
wxchan committed
4
5
6

## Installing Docker

Nikita Titov's avatar
Nikita Titov committed
7
Follow the general installation instructions [on the Docker site](https://docs.docker.com/install/):
wxchan's avatar
wxchan committed
8

Nikita Titov's avatar
Nikita Titov committed
9
10
11
* [macOS](https://docs.docker.com/docker-for-mac/install/)
* [Ubuntu](https://docs.docker.com/install/linux/docker-ce/ubuntu/)
* [Windows](https://docs.docker.com/docker-for-windows/install/)
wxchan's avatar
wxchan committed
12

13
## Using CLI Version of LightGBM via Docker
wxchan's avatar
wxchan committed
14

15
Build a Docker image with LightGBM CLI:
wxchan's avatar
wxchan committed
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
```
mkdir lightgbm-docker
cd lightgbm-docker
wget https://raw.githubusercontent.com/Microsoft/LightGBM/master/docker/dockerfile-cli
docker build -t lightgbm-cli -f dockerfile-cli .
```

where `lightgbm-cli` is the desired Docker image name.

Run the CLI from the container:

```
docker run --rm -it \
--volume $HOME/lgbm.conf:/lgbm.conf \
--volume $HOME/model.txt:/model.txt \
--volume $HOME/tmp:/out \
lightgbm-cli \
config=lgbm.conf
```

Nikita Titov's avatar
Nikita Titov committed
37
In the above example, three volumes are [mounted](https://docs.docker.com/engine/reference/commandline/run/#mount-volume--v---read-only)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from the host machine to the Docker container:

* `lgbm.conf` - task config, for example

```
app=multiclass
num_class=3
task=convert_model
input_model=model.txt
convert_model=/out/predict.cpp
convert_model_language=cpp
```

* `model.txt` - an input file for the task, could be training data or, in this case, a pre-trained model.
* `out` - a directory to store the output of the task, notice that `convert_model` in the task config is using it.

Nikita Titov's avatar
Nikita Titov committed
54
`config=lgbm.conf` is a command-line argument passed to the `lightgbm` executable, more arguments can be passed if required.
55
56
57
58
59
60
61
62
63
64
65

## Running the Python-package Сontainer

Build the container, for Python users:

```
mkdir lightgbm-docker
cd lightgbm-docker
wget https://raw.githubusercontent.com/Microsoft/LightGBM/master/docker/dockerfile-python
docker build -t lightgbm -f dockerfile-python .
```
wxchan's avatar
wxchan committed
66
67
68

After build finished, run the container:

69
70
71
```
docker run --rm -it lightgbm
```
Daniel Nüst's avatar
Daniel Nüst committed
72
73
74
75
76
77
78
79
80
81
82
83

## Running the R-package Сontainer

Build the container based on the [`verse` Rocker image](https://www.rocker-project.org/images/), for R users:

```
mkdir lightgbm-docker
cd lightgbm-docker
wget https://raw.githubusercontent.com/Microsoft/LightGBM/master/docker/dockerfile-r
docker build -t lightgbm-r -f dockerfile-r .
```

84
85
86
87
88
89
90
91
92
93
94
95
This will default to the latest version of R. If you want to try with an older `rocker` container to run a particular version of R, pass in a build arg with [a valid tag](https://hub.docker.com/r/rocker/verse/tags).

For example, to test with R 3.5:

```
docker build \
    -t lightgbm-r-35 \
    -f dockerfile-r \
    --build-arg R_VERSION=3.5 \
    .
```

Daniel Nüst's avatar
Daniel Nüst committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
After the build is finished you have two options to run the container:

1. Start [RStudio](https://www.rstudio.com/products/rstudio/), an interactive development environment, so that you can develop your analysis using LightGBM or simply try out the R package. You can open RStudio in your web browser.
2. Start a regular R session.

In both cases you can simply call

```
library("lightgbm")
```

to load the installed LightGBM R package.

**RStudio**

```
docker run --rm -it -e PASSWORD=lightgbm -p 8787:8787 lightgbm-r
```

Open the browser at http://localhost:8787 and log in.
See the [`rocker/rstudio`](https://hub.docker.com/r/rocker/rstudio) image documentation for further configuration options.

**Regular R**

If you just want a vanilla R process, change the executable of the container:

```
docker run --rm -it lightgbm-r R
```