Run Docker in Ubuntu Live Disk

Run docker in ubuntu live disk

I've managed to make this work by changing the Docker storage to devicemapper instead of AUFS.

If your system doesn't use Systemd

You just have to change /etc/default/docker to have this in it:

DOCKER_OPTS="--storage-driver=devicemapper"

If your system uses Systemd

See this answer and add --storage-driver=devicemapper at the end of the docker start command.

I've manage to make the containers run ok with this, but I prefer using AUFS.

I realized that the partition was not using aufs by default, but something like caw or cow (can't remember now).

I also tried to make it work using AUFS using the union=aufs flag in grub, but when running the docker daemon I get a FATA[0000] Shutting down daemon due to errors: error intializing graphdriver: backing file system is unsupported for this graph driver, that looks related to https://github.com/docker/docker/issues/7321

I'll leave my answer here, since it is a workaround for this problem, but if anyone manage to make this work using AUFS it would be, in my opinion, a better answer.

Is there a way to make a bootable Linux live USB disk from a Linux docker container?

Docker itself doesn't include boot loaders, a kernel, or init. The easiest way to implement this if you really want to use a Docker image is to use another usb bootable Linux distro where you've installed Docker and loaded your image.

Distributions that focus on Docker, though not necessarily booting from USB, include boot2docker and CoreOS. However these are designed to be managed as a Docker host and would require extra work to turn them into something like a kiosk mode that attaches directly to the container on startup.

Outside of Docker, you can take a usb bootable Linux distro and rerun all the commands from your Dockerfile's, including those from the parent Dockerfile. Start from the same base distribution. You will lose the immutability of the image, but remove any of the complexity needed to attach directly to the container on startup.

Mount linux image in docker container


Are there some limitations to docker mounting filesystems?

Yes. A standard Docker container has a number of security restrictions in place. As you have discovered, you can't mount new filesystems. You are also unable to modify the network environment of the container.

One solution is simply to perform the mount operation on the host, and then expose the mounted directory into the container using the -v argument to docker run. Something like:

# losetup -fP --show raspbian.img
/dev/loop0
# mount /dev/loop0p2 /mnt
# docker run -v /mnt:/raspbian ubuntu bash

But if you really want to perform the mount inside the container, you can run a privileged container, using the --privileged option to docker run. This removes most of the restrictions normally placed on a Docker container:

  • You will have complete access to he host's /dev.
  • You will be able to mount filesystems.
  • You will be able to modify the network configuration inside the container.

For example:

# docker run -it --rm --privileged -v /images:/images ubuntu bash

Now I can inspect the image:

root@30f80d4598dc:/# fdisk -l /images/2016-09-23-raspbian-jessie-lite.img 
Disk /images/2016-09-23-raspbian-jessie-lite.img: 1.3 GiB, 1389363200 bytes, 2713600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5a7089a1

Device Boot Start End Sectors Size Id Type
/images/2016-09-23-raspbian-jessie-lite.img1 8192 137215 129024 63M c W95 FAT
/images/2016-09-23-raspbian-jessie-lite.img2 137216 2713599 2576384 1.2G 83 Linux

And mount it:

root@952a75f105ee:/# mount -o loop,offset=$((137216*512))  /images/2016-09-23-raspbian-jessie-lite.img /mnt
root@952a75f105ee:/# ls /mnt
bin dev home lib64 media opt root sbin sys usr
boot etc lib lost+found mnt proc run srv tmp var
root@952a75f105ee:/#

docker:Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Just solved a similar issue with this

The first thing you should do is to have Docker Desktop installed on your pc, of which you can get here https://docs.docker.com/desktop/windows/wsl/

You should also enable wsl2,
Just going through the documentation from the link above should be enough.

Make sure you go into Settings>Resources>WSL Integration and enable Ubuntu-20.04 or any other distro you are using.

Also make sure Settings>General>Use the WSL 2 based engine... box is checked



Related Topics



Leave a reply



Submit