labsoncontainers

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package labsoncontainers allows to create and manage lab environments using Docker Engine API. These environments are designed to practice Computer Science exercises: monitor network traffic, create VPNs, perform mock cyberattacks...

The created containers have the following features:

• Allow interaction with the container (-it)

• Management of network settings (--cap-add=NET_ADMIN)

• Running init system (--init)

• Execution of GUI apps is possible using X11 untrusted cookies (https://github.com/mviereck/x11docker/wiki/X-authentication-with-cookies-and-xhost-("No-protocol-specified"-error)#untrusted-cookie-for-container-applications)

• Home directory is bind mounted on all the lab containers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateEnvironment added in v1.1.0

func CreateEnvironment(labEnv *LabEnvironment) (map[string]string, error)

CreateEnvironment creates a lab environment using Docker Engine SDK and LabEnvironment type.

First, it destroy any other lab environment with the same name using DestroyEnvironment, then it creates all the desired networks and finally, it creates all the containers. On success, it returns a map of the created containers names and their IDs.

Note that, during container creation, it will not be pulled any image, so the desired images will have to be previously built or pulled.

func DestroyEnvironment added in v1.1.0

func DestroyEnvironment(labName string) error

DestroyEnvironment removes all containers (including running containers), networks and the X11 cookie directory of the provided lab environment.

func GetEnvironmentNetworks added in v1.1.0

func GetEnvironmentNetworks(labName string) ([]string, error)

GetEnvironmentNetworks gets all networks IDs that belong to the provided lab environment.

func InspectEnvironment added in v1.1.0

func InspectEnvironment(labName string) (map[string][]byte, error)

InspectEnvironment returns low-level information of all the containers of the provided lab environment. On success, it returns a map of the containers' names as keys and their information as values.

func StartEnvironment added in v1.1.0

func StartEnvironment(labName string) error

StartEnvironment starts all the containers of the provided lab environment.

func StopEnvironment added in v1.1.0

func StopEnvironment(labName string) error

StopEnvironment stops all containers of the provided lab environment.

Types

type LabContainer

type LabContainer struct {
	Name       string       `yaml:"nombre"`
	Image      string       `yaml:"imagen"`
	Networks   []LabNetwork `yaml:"redes"`
	Background bool         `yaml:"background,omitempty"`
	ID         string
}

LabContainer represents the structure of a lab container. It is composed by its name, the image name the container will use, a list of LabNetwork and the background field: if it is set to true, a terminal window will not be created for interacting with the container.

func GetEnvironmentContainers added in v1.1.0

func GetEnvironmentContainers(labName string) ([]LabContainer, error)

GetEnvironmentContainers gets all containers info (including non-running containers) that belong to the provided lab environment.

type LabEnvironment added in v1.1.0

type LabEnvironment struct {
	LabName    string         `yaml:"nombre_practica"`
	Containers []LabContainer `yaml:"contenedores"`
}

LabEnvironment represents the structure of a lab environment. It is composed by the lab name and a list of LabContainer.

type LabNetwork

type LabNetwork struct {
	Name string `yaml:"nombre"`
	IP   string `yaml:"ip"`
}

LabNetwork represents the structure of a lab network. It is composed by its name and, optionally, the IP that will be used by the container in the network.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL