简体   繁体   中英

Run docker in ubuntu live disk

I was wondering if it's possible to install and run Docker in a Ubuntu 14.04 USB Live-Disk .

I'm trying it with a 8GB USB, 4 GB for installation and 4 GB for persisted storage , but I keep getting errors when running the containers ( no problem in pulling them ).

Here is my Docker version:

$ sudo docker version
Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.4.2
Git commit (client): 7c8fca2
OS/Arch (client): linux/amd64
Server version: 1.6.2
Server API version: 1.18
Go version (server): go1.4.2
Git commit (server): 7c8fca2
OS/Arch (server): linux/amd64

And the current error I'm getting when running a docker container is:

[8] System error: mountpoint for cpu not found 

OBS: Sometimes the error is that the cpuset or that the devices were not found.

The kernel of the live-disk that I'm using is:

$ uname -r
3.13.0-32-generic

If the Ubuntu live disk is not the best live-disk to run Docker, are there any other alternatives that have some GUI with it , not just a simple terminal to run docker?

I'm saying this because I'm trying to introduce Docker to my parents, but they don't want to install a linux in their PCs, and so I need some simple graphic interface to write down the Dockerfile, open a browser, etc...


UPDATE

I saw that during the install there was a error when setting up the cgroup-lite dependency initctl: Unknown job: cgroup-lite . Also I read that some ubuntu need to install apparmor so that the docker installation works properly.

So I installed it and reinstalled docker (cgroup-lite installed with no problem then), and now I'm getting this when running the sudo docker -d

INFO[0000] +job serveapi(unix:///var/run/docker.sock)   
INFO[0000] Listening for HTTP on unix (/var/run/docker.sock) 
INFO[0000] +job init_networkdriver()                    
INFO[0000] -job init_networkdriver() = OK (0)           
WARN[0004] Your kernel does not support cgroup swap limit. 
INFO[0004] Loading containers: start.                   
......
INFO[0004] Loading containers: done.                    
INFO[0004] docker daemon: 1.6.2 7c8fca2; execdriver: native-0.2; graphdriver: aufs 
INFO[0004] +job acceptconnections()                     
INFO[0004] -job acceptconnections() = OK (0)            
INFO[0004] Daemon has completed initialization 

And when trying to run a container I receive>

ERRO[0125] HTTP Error: statusCode=500 Cannot start container 90875e79dec37cec41a67aac235b81f0fc17c4e011cd6e5368a4b29336587f5b: 
[8] System error: permission denied

Not sure about the kernel not supporting cgroup, but if so, then is it possible to update the kernel in the livedisk (persisting it?) ?

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.

You want to tell the Docker daemon to store the data related to your containers on the persistent storage.

By default the docker daemon put those data into /var/lib/docker . You can change that location with the--graph docker daemon option

I had a similar problem on Debian Live system. For the latest docker, changing the /etc/default/docker is not making any change.

Appending --storage-driver=vfs to the /lib/systemd/system/docker.service just helped for me:

...
ExecStart=/usr/bin/dockerd --storage-driver=vfs -H fd://
...

( vfs may have poor performance, but aufs , overlay2 and devicemapper were not working properly for me.)

A simpler modern approach

The following doesn't work in Ubuntu 14.04, but it does work in 20.04 , 18.04 , and 16.04 .

Prerequisite: install Docker on the LiveUSB

If you haven't already installed Docker, start a terminal and paste the following commands.

# docker.io is in the "universe" repository, so add it.
sudo add-apt-repository universe

# Only necessary in 16.04, but doesn't hurt anything.
sudo apt-get update

# Install Ubuntu's Docker package
sudo apt-get install -y docker.io

The solution:

Here we use the /etc/docker/daemon.json configuration file to change the storage driver.

Paste the following commands in a terminal:

# Create a config file to set the storage driver to "Device Mapper"
echo '{ "storage-driver": "devicemapper" }' | sudo tee -a /etc/docker/daemon.json > /dev/null

# Restart the Docker service
sudo service docker restart

Test

Now I can successfully run an Ubuntu container with the command

sudo docker run --rm -it ubuntu

Bad news for the future

Unfortunately, I'm not sure how much longer this approach will be supported. Running sudo docker info I see the following deprecation warning:

WARNING: the devicemapper storage-driver is deprecated, and will be removed in a future
release.

I had similar issues but with Ubuntu 16.04. What I actually did to make it run

1) I installed docker on ubuntu live

    sudo apt-get update

    sudo apt-get install \
      apt-transport-https \
      ca-certificates \
      curl \
      gnupg-agent \

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
      software-properties-common

    sudo apt-key fingerprint 0EBFCD88

    sudo add-apt-repository \
       "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
       $(lsb_release -cs) \
       stable"

    sudo apt-get update

    sudo apt-get install docker-ce docker-ce-cli containerd.io

2) Once docker is installed on ubuntu live. You need to stop the docker using

    sudo service docker stop

3) Then edit the file on /lib/systemd/system/docker.service using

    sudo gedit /lib/systemd/system/docker.service

by replacing this line

    ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd  /containerd.sock

with this line

    ExecStart=/usr/bin/dockerd -g /media/ubuntu/something -H fd:// --containerd=/run/containerd  /containerd.sock

So basically what we have done is to add -g /media/ubuntu/something, which is the driver that will replace the ROOT DIR of docker. Note that if the driver is NTFS, this won't work. You need to have the driver as ext4 or FAT.

4) Once finished, reload the daemon

    sudo systemctl daemon-reload

5) restart the docker service

    sudo service docker restart

6) check that the ROOT DIR has changed by running

    sudo docker info

You should see the new directory there. After all, this is very cool since you can have portable images and containers and you can run them on any ubuntu machine just by doing the aforementioned. I haven't tested this on Windows but anyway it has always been painful for me to work with docker and windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM