15

I wanna create a docker image from an ISO file. and I meet the same question like this iso to docker file

I did same operations with him , and I know it's wrong now.

now what i have is:

  • an ISO file. my own ISO file, based on ubuntu but it's not ubuntu.
  • a computer, running ubuntu on it.

and I wanna know the detail operations to create a docker image from this ISO file.

if use VM, I hope i could get certainly operations. or if don't need VM, what should I do ?

I have searched many docs... like make a qcow2 from iso file, like debootstrap .. but these docs are not quite clearly and confused me a lot ...

I really wanna know detail operations, like this:

sudo mount -o loop CentOS-6.4-x86_64-minimal.iso /media/cdrom

sudo tar -C /media/cdrom -c . | docker import - flores314/centos2:new

although it is wrong, but it is clear.

If it is not clear, it will really really confused people like me ...

Thanks !!!

Community
  • 1
  • 1
李浩然
  • 243
  • 1
  • 3
  • 9
  • I'm not really clear on what you mean: you have 2 commands there, but you say "it is wrong". What's wrong with them? Did you try them and get an error? If so, what error? Where did they come from? – Nanne Feb 22 '17 at 08:06
  • @Nanne I think he means that he wants a step by step explanation including the commands he should run. – J. Meijers Feb 22 '17 at 09:34
  • I have not tried it, but you can use docker import to do this. You need a tarballl for that, and that command looks like it makes a tarball, then pipes it to docker import. That tarball is made from a dir, and the first command mounts that iso to that dir. So this does looks at least like a feasible set of commands, that had to come from somewhere. So i'd like to know what's wrong with them, as they look ok, and where they came from, to see what explanation is missing. – Nanne Feb 22 '17 at 10:35
  • this image could not run. cause this is wrong way to make docker image. it didn't get the rootfs in iso. I found reason in this link https://groups.google.com/forum/#!msg/docker-user/TGvzjR4afzI/aIA-nQSZGq0J – 李浩然 Feb 22 '17 at 10:41

3 Answers3

8

docker import can make your work easy. I found a useful article for this https://medium.com/@SofianeHamlaoui/convert-iso-images-to-docker-images-4e1b1b637d75

Abhinav Sharma
  • 147
  • 2
  • 9
2

Basically, converting an ISO to a docker container, is something you can't do verbatim. This is because one is a disk image, where the other is a complete container that also includes a filesystem.

It is possible though to create a new container, mount the iso and copy the contents into the FileSystem. I'm not sure if you're going to find anyone here who will write a list of commands that you should run to achieve this. If you start trying though and explain what you are doing and what problems you are running into, you will find that the people here are more than helpfull!

J. Meijers
  • 949
  • 8
  • 14
  • I'm curious why the `docker import` from the question wouldn't work? It does sound legit :) – Nanne Feb 22 '17 at 10:37
  • @Nanne, to be honest I was not aware that it was this easy – J. Meijers Feb 22 '17 at 10:46
  • ```wget https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1808.qcow2 sudo apt-get -y install libguestfs-tools sudo virt-tar-out -a CentOS-7-x86_64-GenericCloud-1808.qcow2 / - | gzip --best > centos.tgz cat centos.tgz | docker import - centos:base``` – Herve Meftah Jun 12 '20 at 13:20
0

By the looks of it you already have the ISO to work with. Just traverse to where the rootfs is located and go from there:

(Make sure to note where you need to substitute your filenames/directories because I use arbitrary names here in the example below)

mkdir /mnt/ubuntu-iso
mount -o loop Ubuntu.iso /mnt/ubuntu-iso
cd /mnt/ubuntu.iso/casper

I found that in the Ubuntu ISO there is a directory casper that contains the rootfs. Get to that directory and you will find a file called filesystem.squashfs move that to a place where you prefer to work on it.

mkdir ~/Ubuntu-Squashfs
mv filesystem.squashfs ~/Ubuntu-Squashfs
cd ~/Ubuntu-Squashfs
unsquashfs filesystem.squashfs

From there run the unsquashfs command to get to the contents of the rootfs. At this point is where you will tar the directory of the rootfs and pass that off to docker.

tar -czf ubuntu.tar.gz squashfs-root

This will leave you with an archive of tar.gz which you can then use with docker:

docker import ubuntu.tar.gz custom-rootfs/bionic
docker image list

After you run the docker image list command you will see your custom rootfs be available as a docker image.

Of course you can skip alot of the mount unsquashfs & tar commands by just downloading an archive of the Ubuntu rootfs from here

tijko
  • 7,599
  • 11
  • 44
  • 64