Convert ISO images to docker images
Tags: sofianehamlaoui, dockerimage, converting, iso
Published: 2019-12-16 03:32:54

---
title: Convert ISO images to docker images
published: true
date: 2019-09-17 18:16:03 UTC
tags: sofiane-hamlaoui,docker-image,converting,iso
canonical_url: 
---

### 🐳 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_**](https://en.wikipedia.org/wiki/Live_CD) **_,_** means a bootable version of the operating system.

### Before Starting ! :

In this tutorial/story, I’ll use Ubuntu 18.04.3 [LTS](https://en.wikipedia.org/wiki/Long-term_support)’s live disc ISO,

### Keywords :

- **_rootfs_**  : a [file system](https://en.wikipedia.org/wiki/File_system). In [Linux](https://en.wikipedia.org/wiki/Linux), all file systems have a mount point, which is the directory where the mounted file system connects to the root file system
- **_squashfs :_** a [compressed](https://en.wikipedia.org/wiki/Data_compression) read-only [file system](https://en.wikipedia.org/wiki/File_system) for [Linux](https://en.wikipedia.org/wiki/Linux)
- **_unsquashfs :_** a tool to [uncompress](https://en.wikipedia.org/wiki/Data_compression) squashfs [file systems](https://en.wikipedia.org/wiki/File_system)

### Requirments :

- **_squashfs-tools :_** install [squashfs-tools](https://www.tldp.org/HOWTO/html_single/SquashFS-HOWTO/) in your system
- Downlading the LiveCD ISO version

![](https://cdn-images-1.medium.com/max/689/1*5iKRJRqEauoShmFeUK0CEg.png)<figcaption>ISO file downloaded &amp; squashfs-tools installed</figcaption>

### Let’s start ! :

**_1- Start by creating the 2 folders (rootfs and unsquashfs)_**

```
$: mkdir rootfs unquashfs
```

![](https://cdn-images-1.medium.com/max/689/1*NURaMl8Ci4YwdiiQtStmOw.png)<figcaption>Creating rootfs &amp; unsquashfs folders</figcaption>

**_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
```

![](https://cdn-images-1.medium.com/max/738/1*TsYCriGIdOADKWutnvevNA.png)<figcaption>Mounting the ISO file</figcaption>

**_3- Find the filesystem.squashfs file_**

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

![](https://cdn-images-1.medium.com/max/737/1*-E1VJCkjliKF50-yftzmhg.png)<figcaption>Finding the filesystem.squashfs file</figcaption>

**_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
```

![](https://cdn-images-1.medium.com/max/739/1*1VvqdeBDYCkPLqe5IhQ4HA.png)<figcaption>Extractingthe filesystem files to the unsquashfs folder</figcaption>

**_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
```

**_6- you will get a sha256 hash (somthing like this )_**

```
$:sha256:qf917d58831f926c6b93ff84bd6az68550a6cd6c36aeb6c837c53d655d9453sh
```

![](https://cdn-images-1.medium.com/max/683/1*Qi0hAgYD_Z1ZbpQdYKcAcA.jpeg)<figcaption><strong><em>Compressing then importing the image using docker</em></strong></figcaption>

**_7- test your docker image :_**

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

![](https://cdn-images-1.medium.com/max/965/1*ZRWqyHmN1z8ivdzJLKr7zA.png)<figcaption>Docker images</figcaption>

![](https://cdn-images-1.medium.com/max/683/1*xe0m7QiM-0c-XBl3oizNtw.png)<figcaption>Your docker image is READY!</figcaption>

And here you go !

Thank you for reading,

#### My Twitter :

[Sofiane Hamlaoui](https://twitter.com/S0fianeHamlaoui)

#### **My Github :**

[SofianeHamlaoui - Overview](https://github.com/SofianeHamlaoui)

#### Support me :

- Paypal : [paypal.me/SofianeHamlaoui](http://paypal.me/SofianeHamlaoui)
- BTC : 1NR2oqsuevvWJwzCyhBXmqEA5eYAaSoJFk