Installing Docker in EVE-NG

Docker is a platform which allows you to create an application which can be run in a loosely isolated enviroment. When combined with EVE-NG, we can quickly create applications inside our lab envrioment. An example of this is, instead of insalling a linux server with apache, you can just deploy a prebuilt docker container with apache already installed and configured. This container can then be connected to a virtual router in your lab.

Prerequisites

This Document assumes you already have a EVE-NG installation up and running.

Installing Docker

The easiest way to get started is using the prebuilt docker package in the official ubuntu repository.

1
sudo apt-get install docker.io

After installing, we will make some modifications to our docker config file. EVE-NG is built on top of Ubuntu 16.04 so it utilizes systemd. The perfered method of managing the docker configuration file is to use the daemon json.
To do this, we need to create a file which overrides the execstart parameters. We must do this because the default execstart statement has a host paramater which will conflict with the options given later in our json file.

1
2
3
4
vim /etc/systemd/system/docker.service.d/service.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd

Next we will create our json configuration file.

Formatting Mistakes
Pay attention to the format because if you make a formatting mistake, the daemon won’t start.

1
2
3
4
5
6
7
8
9
10
/etc/docker/daemon.json
{
 “hosts”: [“tcp://127.0.0.1:4243”, “unix:///var/run/docker.sock”],
 “storage-driver”: “overlay2”,
 “log-driver”: “json-file”,
 “log-opts”: {
 “max-size”: “10m``”,
 “max-file”: “2
 }
}

After making these changes we will need to reload the daemon config and restart the service.

1
sudo systemctl daemon-reload && systemctl restart docker;

We can now verify that the process is running.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@lab:~# systemctl status docker.service
* docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e
Drop-In: /etc/systemd/system/docker.service.d
`-service.conf
Active: active (running) since Wed 2017-08-16 12:51:07 EEST; 6 days ago
Docs: https://docs.docker.com
Main PID: 31852 (dockerd)
Tasks: 51
Memory: 452.3M
CPU: 42min 43.749s
CGroup: /system.slice/docker.service
|-31852 /usr/bin/dockerd
`-31861 containerd -l unix:///var/run/docker/libcontainerd/docker-con

Modifying EVE-NG

EVE-NG has support for Docker built in but it is currently commented out. In order to get things working, we’ll need to modify some files.

Uncomment template

You’ll need to uncomment the following line in the init.php file. This will allow EVE-NG to use the docker template.
vim /opt/unet/html/includes/init.php

1
2
//'docker' => 'Docker.io',
'docker' => 'Docker.io',

Modify CLI.php

Docker nodes can have 1 of 4 different states inside EVE-NG. The states are:

  • 0 - Stopped
  • 1 - Stopped (Locked)
  • 2 - Running
  • 3 - Running (Locked)

There is an issue in the current code where after stopping a docker node, the state is locked which prevents it from being started.

The following patch comments out the creating of the lock file when a docker node is started.

1
patch -p0 < cli.patch
1
2
3
4
5
6
7
8
9
10
+++ cli.php 2017-08-12 17:42:15.592261956 +0000
@@ -1053,7 +1053,7 @@
}
// Start configuration process
- //touch($n -> getRunningPath().'/.lock');
+ touch($n -> getRunningPath().'/.lock');
//$cmd = 'nohup /opt/unetlab/scripts/config_'.$n -> getTemplate().'.py -a put -i '.$n -> getUuid().' -f '.$n -> getRunningPath().'/startup-config -t '.($n -> getDelay() + 300).' > /dev/null 2>&1 &';
$cmd = 'nohup /opt/unetlab/scripts/'.$GLOBALS['node_config'][$n -> getTemplate()].' -a put -i '.$n -> getUuid().' -f '.$n -> getRunningPath().'/startup-config -t '.($n -> getDelay() + 300).' > /dev/null 2>&1 &';
exec($cmd, $o, $rc);

Adding Docker Images

There is a public registry available that you can use to download existing docker images that others have built.

Custom Docker Images
Another option is to extend existing public iages or building your own from scratch

THe following command will attempt to install the docker image if it is found locally. If the image is not available locally, it will be downloaded from the docker repository online.

1
docker pull <image_name>