== 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.[[BR]] In Virtualbox, correct 'Extension pack' should be installed. '''VM Setup''' Download VM from the following Link. ​https://docs.learn.ac.lk/index.php/s/YcojJ2544b40Zw4 Import the VM to Virtualbox.[[BR]] Username and Password: '''docker''' [[BR]] May have to create Virtualbox Host-Only Network Adapter[[BR]] {{{ File > Host Network Manager > Create }}} Test internet connectivity.[[BR]] 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 (Put an application name as image name, e.g.: apache) {{{ docker search }}} Download a Docker image {{{ docker pull }}} List docker containers that are currently running {{{ docker container ls }}} Run a Docker image of a web server {{{ docker run -d --name -p 80:80 -d }}} Stop a Docker container {{{ docker stop }}} '''Setup a Docker image''' Create a directory and go inside it. {{{ mkdir cd }}} Make '''Dockerfile''' and insert the following content to it. {{{ nano Dockerfile }}} {{{ 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. {{{ }}} '''Docker Hub Account Setup''' Go to https://hub.docker.com/signup [[BR]] Create an account[[BR]] Choose ‘Personal Plan’ (Continue with free) if asked[[BR]] Create a '''Repository''' '''Build a Docker image''' {{{ docker build . -t /:v1 }}} . '''Share a Docker image''' {{{ docker login -u docker push /: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.[[BR]] Username and Password: '''docker''' [[BR]] May have to create Virtualbox Host-Only Network Adapter[[BR]] {{{ File > Host Network Manager > Create }}} Test internet connectivity.[[BR]] 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 }}} Login to container {{{ lxc exec test-ct bash }}} Make a snapshot {{{ lxc snapshot test-ct test-ct1 }}} Delete a container {{{ lxc stop test-ct lxc delete --force test-ct }}}