DEV Community

Sofiane Hamlaoui
Sofiane Hamlaoui

Posted on • Originally published at Medium on

14 1

Convert ISO images to docker images

🐳 Convert ISO images to docker images

Yep! I was looking for a method or a trick to convert ISO files to docker images, It was hard to find one ! But the only one was not really explained and lacking some information. So here we are !!

Choosing the ISO file :

Well before starting the process ! Keep in mind that you have to use a live disc , means a bootable version of the operating system.

Before Starting ! :

In this tutorial/story, I’ll use Ubuntu 18.04.3 LTS’s live disc ISO,

Keywords :

Requirments :

  • squashfs-tools : install squashfs-tools in your system
  • Downlading the LiveCD ISO version

ISO file downloaded & squashfs-tools installed

Let’s start ! :

1- Start by creating the 2 folders (rootfs and unsquashfs)



$: mkdir rootfs unquashfs


Enter fullscreen mode Exit fullscreen mode

Creating rootfs & unsquashfs folders

2- mount your ISO file to the rootfs folder as a loop device



$: sudo mount -o loop ubuntu-18.04.3-desktop-amd64.iso rootfs


Enter fullscreen mode Exit fullscreen mode

Mounting the ISO file

3- Find the filesystem.squashfs file



$: find . -type f | grep filesystem.squashfs


Enter fullscreen mode Exit fullscreen mode

Finding the filesystem.squashfs file

4- use unsquashfs to extract filesystem files to the unsquashfs folder (that would take between 5–10mins)



$: sudo unsquashfs -f -d unsquashfs/ rootfs/casper/filesystem.squashfs


Enter fullscreen mode Exit fullscreen mode

Extractingthe filesystem files to the unsquashfs folder

5- compress and import the image using docker (that would take some time 10–20 mins)



$: sudo tar -C unsquashfs -c . | docker import - sofiane/myimg


Enter fullscreen mode Exit fullscreen mode

6- you will get a sha256 hash (somthing like this )



$:sha256:qf917d58831f926c6b93ff84bd6az68550a6cd6c36aeb6c837c53d655d9453sh


Enter fullscreen mode Exit fullscreen mode

Compressing then importing the image using docker

7- test your docker image :



$:docker run -h ubuntu -i -t sofiane/myimg bash


Enter fullscreen mode Exit fullscreen mode

Docker images

Your docker image is READY!

And here you go !

Thank you for reading,

My Twitter :

Sofiane Hamlaoui

My Github :

SofianeHamlaoui - Overview

Support me :

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (1)

Collapse
 
sohojmanush profile image
sohojmanush

How do I convert a non live CD into a docker image? I have a distro for RPI (install only), which doesn't contains any squashfs filesystem.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay