Docker Notes
How to use docker

How to create a docker image from a linux disto ISO
How to create a fresh linux distro from a live ISO

Creating a docker image from a live ISO
Download Live ISO, example  

 Example: debian ISO: debian-live-13.1.0-amd64-standard.iso 

 https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/ 

 Make a directory to mount the ISO 

 sudo mkdir /media/iso 

 Mount the ISO to the /media/iso 

 sudo mount -o loop debian-live-13.1.0-amd64-standard.iso /media/iso 

 Extract the Root Filesystem using SquashFS 

 sudo unsquashfs -d debian-fs /media/iso/live/filesystem.squashfs 

 Delete unnecessary files 

 sudo rm -rf "debian-fs/proc" "debian-fs/sys" "debian-fs/dev" "debian-fs/run" 

 Create a compressed file of the root filesystem 

 sudo tar -C debian-fs -czf debian-fs.tar.gz . 

 Import the compressed Debian filesystem into Docker as an Image 

 cat debian-fs.tar.gz | docker import - debian-image:latest 

 Run the Docker Container 

 docker run -it debian-image /bin/bash 

 

 Script to create a Debian Docker Image from a Debian ISO 

 #!/bin/bash

DEBIAN_ISO="debian-live-13.1.0-amd64-standard.iso"

MOUNT_DIR="/media/iso"

EXTRACT_DIR="./debian-fs"

TARBALL_NAME="debian-fs.tar.gz"

DOCKER_IMAGE_NAME="debian-image:latest"

sudo mkdir -p "$MOUNT_DIR"

sudo mount -o loop "$DEBIAN_ISO" "$MOUNT_DIR"

sudo unsquashfs -d "$EXTRACT_DIR" "$MOUNT_DIR/live/filesystem.squashfs"

sudo rm -rf "$EXTRACT_DIR/proc" "$EXTRACT_DIR/sys" "$EXTRACT_DIR/dev" "$EXTRACT_DIR/run"

sudo tar -C "$EXTRACT_DIR" -czf "$TARBALL_NAME" .

cat "$TARBALL_NAME" | docker import - "$DOCKER_IMAGE_NAME"

echo "Run your new Debian Docker image with:"

echo " docker run -it $DOCKER_IMAGE_NAME /bin/bash"