wiki:Csle2022/Agenda/Containers

Version 9 (modified by dushmantha, 2 years ago) ( diff )

--

Docker Lab

In this lab, you will setup Docker and customize Docker images.

Requirements:

Participants are requested to have a computer with Windows 8/10/11 (8GB RAM, 25GB free disk space) with Virtualbox (version 6 or higher) hypervisor and PuTTY installed.

In Virtualbox, 'Extension pack' should be installed.

A wired internet connection is preferred.

VM Setup

Download VM from the following Link.

https://docs.learn.ac.lk/index.php/s/YcojJ2544b40Zw4

Import the VM to Virtualbox.

Username and Password: docker

May have to create Virtualbox Host-Only Network Adapter

File > Host Network Manager > Create

Test internet connectivity.

Login using Putty.

Login as root to the provided VM.

Setup Docker

apt-get install -y docker.io
systemctl enable docker.service

Managing Docker

List Docker images

docker image ls

Docker image search

docker search <image name>

Download a Docker image

docker pull <image name>

List docker containers that are currently running

docker container ls

Run a Docker image

docker run -d --name <name> -p 80:80 -d <image name>

Stop a Docker container

docker stop <container name/ID>

Setup a Docker image

Create a directory and go inside it.

mkdir <directory name>
cd <directory name>

Make Dockerfile and insert the following content to it.

FROM php:8.0-apache
COPY index.php /var/www/html/
EXPOSE 80
CMD apachectl -D FOREGROUND

Make index.php and insert the following content to it.

<!DOCTYPE html>
<html>
<body>
<?php
date_default_timezone_set("Asia/Colombo");
echo "The time is " . date("h:i:sa");
?>
</body>
</html>

Docker Hub Account Setup

Go to https://hub.docker.com/signup

Create an account

Choose ‘Personal Plan’ (Continue with free) if asked

Create a Repository

Build a Docker image

docker build . -t <Docker Hub username>/<repository name>:v1

.

Share a Docker image

docker login -u <docker hub username>
docker push <docker hub username>/<respository name>:v1
docker logout

Now you can view the uploaded Docker image in your Docker Hub account.

LXC Lab

In this lab, you will setup a LXC.

Requirements:

Same as the above Docker lab.

Virtual Machine (VM) Setup

Download VM from the following Link.

https://docs.learn.ac.lk/index.php/s/YcojJ2544b40Zw4

Import the VM to Virtualbox.

Username and Password: docker

May have to create Virtualbox Host-Only Network Adapter

File > Host Network Manager > Create

Test internet connectivity.

Login as root using PuTTY.

Setup LXC

Initiate LXC.

lxd init
Would you like to use LXD clustering? (yes/no) [default=no]:
Do you want to configure a new storage pool? (yes/no) [default=yes]:
Name of the new storage pool [default=default]:
Name of the storage backend to use (btrfs, dir, lvm) [default=btrfs]: dir
Would you like to connect to a MAAS server? (yes/no) [default=no]:
Would you like to create a new local network bridge? (yes/no) [default=yes]: no
Would you like to configure LXD to use an existing bridge or host interface? (yes/no) [default=no]: no
Would you like LXD to be available over the network? (yes/no) [default=no]:
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]:

Edit network configuration.

vi /etc/netplan/00-installer-config.yaml

Make sure you edit the network interfaces as per your installation details. Don't remove any interface.

network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: yes
    bridges:
      lxdbr0:
        dhcp4: yes
        interfaces:
          - enp0s3
netplan apply

Modify the default container profile to add bridged network.

lxc profile edit default
config: {}
description: Default LXD profile
devices:
  eth0:
    nictype: bridged
    parent: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: default
used_by: []

Check remote repositories

lxc remote list

Local repositories

lxc image list

Check remote images.

lxc image list images:
lxc image list images:ubuntu

Create a Ubuntu Container.

lxc launch ubuntu:22.04 test-ct
lxc list

Delete a container

lxc stop test-ct
lxc delete --force test-ct

Cloning

Note: See TracWiki for help on using the wiki.