Docker - ISO Mounting to Container - Ubuntu Server Full Image

Issue
The below command is meant to mount an iso image into a docker container:
Command

  • #!/bin/bash
  • mount -o loop,ro ubuntu-16.04.4-server-amd64.iso /tmp/iso-mount
  • top_dir_mounts=()
  • for i in bin etc lib usr var
  • do
  • top_dir_mounts+=(-v “/tmp/iso-mount/$i:/$i”)
  • done
  • docker run --rm “${top_dir_mounts[@]}” --tmpfs /tmp --tmpfs /run routers_17418

OS Version/build
Ubuntu 16.04 4.13.0-38-generic

What I what to do is to mount an iso image of a ubuntu server, as I require a full ubuntu image within a container.

Any Help?

Thank you

If you really require a full OS – init system, desktop environment, and all – it sounds like you’re looking for more like a standard virtualization system. VirtualBox is a straightforward option that runs on most mainstream operating systems.

When you start saying “ISO image” and “mount into a container” you’ve gotten well outside the space Docker is good at. I’d recommend reading Docker’s official tutorial on building and using custom images. If this doesn’t sound like something you could readily adapt for your use case then I’d focus more on full virtualization solutions.

I’d suggest:

  • Docker is good when you control your application’s build system; you have simple TCP-based (often HTTP) services; communication between services is only over the network, not shared files; you don’t need much from your OS beyond a language runtime

  • VMs are good when you need to run multiple components with shared filesystem state; you need a complex network topology; your application needs complex OS interactions like mounting filesystems or a local service bus

  • Host applications are good for software developers; when you need to directly manage the host; when you need access to the host’s hardware devices; for interactive desktop applications

Hello,

Yes - I guess this is somewhat counter to the whole Docker image philosophy :slight_smile:
BUT - I have a image I do not want to rebuild / reload for a monitoring tool that is currently running - I’m trying to test an update to that tool and i needs some extra fonts - i was trying to load the font from the OS image… but the mount -o loop fails.

mount -o loop /usr/Spectrum/custom/ISO/rhel-server-7.5-x86_64-dvd.iso /media/

mount: /usr/Spectrum/custom/ISO/rhel-server-7.5-x86_64-dvd.iso: failed to setup loop device: No such file or directory

( This image is successfully mounted on the hosting parent and is being made available to the Image using a docker volume that was built to preserve data between Instantiations )

This problem was listed as a Issue with RHE 6.x that should have been corrected in 7.x
This was supposed to Fix the issues - but it does not.

modprobe loop
loop: module loaded

So any help on why this doesn’t work Even if it’s a Bad Idea would be appreciated,

Thank you,
DonL
PS: There’s No thread like an Old Thread…

Woo Hoo !
A solution - I added a volume to the container to enable persistent data from the Application between iterations.

I mounted the ISO to the shared Volume
mount -o loop /var/lib/docker/volumes/spectrum-custom/_data/ISO/rhel-server-7.5-x86_64-dvd.iso /var/lib/docker/volumes/spectrum-custom/_data/media

create my etc/yum repo file on the container and Voila !

Well you could do so … although this is way out of scope of the docker/container philosophy. Leaving security issues outside, you’re trying to access/use binaries and scripts that “may” have links/dependencies to other files outside the directories you’ve mounted. If all that stuff is really needed I strongly agree with dmaze’s suggestion to use a VM instead of a container.
However, it might be worth a try to build the container “from scratch” using your machines OS as a “base image” (instead of pulling one from docker.io).
Simply replace the

“FROM ubuntu:16.04”

with

“FROM scratch”

in your Dockerfile and build the whole thing …
(you may want to look ath this first: https://www.mgasch.com/post/scratch/ )