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 ¶
- func CreateEnvironment(labEnv *LabEnvironment) (map[string]string, error)
- func DestroyEnvironment(labName string) error
- func GetEnvironmentNetworks(labName string) ([]string, error)
- func InspectEnvironment(labName string) (map[string][]byte, error)
- func StartEnvironment(labName string) error
- func StopEnvironment(labName string) error
- type LabContainer
- type LabEnvironment
- type LabNetwork
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
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
GetEnvironmentNetworks gets all networks IDs that belong to the provided lab environment.
func InspectEnvironment ¶ added in v1.1.0
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
StartEnvironment starts all the containers of the provided lab environment.
func StopEnvironment ¶ added in v1.1.0
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 ¶
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.