Install Docker binary on a server without root access

Viewed 3979

I have a server by a provider without any root access. It is not possible to write scripts in /etc/ or /var/lib/docker. Docker is not installed. My idea is to install and run docker binary in directory. I will install docker with a shell script. The script should be able to be started from any directory without root access.

When the script starts ./docker/dockerd --data-root=docker/var/lib/docker I get this error message.

WARN[2018-11-17T18:26:19.492488618+01:00] Error while setting daemon root propagation, this is not generally critical but may cause some functionality to not work or fallback to less desirable behavior dir=docker/var/lib/docker error="error getting daemon root's parent mount: open /proc/self/mountinfo: permission denied" Error starting daemon: open /var/run/docker.pid: permission denied

dockerd has so many parameter. Here for the pidfile: -p | **--pidfile*[=/var/run/docker.pid]

http://manpages.ubuntu.com/manpages/cosmic/man8/dockerd.8.html

Thank you for the help

#!/bin/bash

DOCKER_RELEASE='docker-18.06.1-ce.tgz'

wget https://download.docker.com/linux/static/stable/x86_64/$DOCKER_RELEASE
tar xzvf $DOCKER_RELEASE
rm $DOCKER_RELEASE

./docker/dockerd --data-root=docker/var/lib/docker
2 Answers

As announced today (Feb. 4th, 2019) by Akihiro Suda:

Finally, it is now possible to run upstream dockerd as an unprivileged user!

See moby/moby PR 38050:

Allow running dockerd in an unprivileged user namespace (rootless mode).
Close #37375 "Proposal: allow running dockerd as an unprivileged user (aka rootless mode)", opened in June 2018

No SETUID/SETCAP binary is required, except newuidmap and newgidmap.

How I did it:

By using user_namespaces(7), mount_namespaces(7), network_namespaces(7), and slirp4netns.

Warning, there are restrictions:

Restrictions:

  • Only vfs graphdriver is supported.
    However, on Ubuntu and a few distros, overlay2 and overlay are also supported.
    Starting with Linux 4.18, we will be also able to implement FUSE snapshotters.

(See Graphdriver plugins, where Docker graph driver plugins enable admins to use an external/out-of-process graph driver for use with Docker engine.
This is an alternative to using the built-in storage drivers, such as aufs/overlay/devicemapper/btrfs.)

  • Cgroups (including docker top) and AppArmor are disabled at the moment.
    In future, Cgroups will be optionally available when delegation permission is configured on the host.
  • Checkpoint is not supported at the moment.
  • Running rootless dockerd in rootless/rootful dockerd is also possible, but not fully tested.

The documentation is now in docs/rootless.md:

Note the following requirements:

  • newuidmap and newgidmap need to be installed on the host.
    These commands are provided by the uidmap package on most distros.

  • /etc/subuid and /etc/subgid should contain >= 65536 sub-IDs.
    e.g. penguin:231072:65536.

That is:

$ id -u
1001
$ whoami
penguin
$ grep ^$(whoami): /etc/subuid
penguin:231072:65536
$ grep ^$(whoami): /etc/subgid
penguin:231072:65536

Either slirp4netns (v0.3+) or VPNKit needs to be installed.
slirp4netns is preferred for the best performance.

You will have to modify your script:

You need to run dockerd-rootless.sh instead of dockerd.

$ dockerd-rootless.sh --experimental"

Update May 2019: Tõnis Tiigi does explore this rootless option with "Experimenting with Rootless Docker":

User namespaces map a range of user ID-s so that the root user in the inner namespace maps to an unprivileged range in the parent namespace.
A fresh process in user namespace also picks up a full set of process capabilities.

The rootless mode works in a similar way, except we create a user namespace first and start the daemon already in the remapped namespace. The daemon and the containers will both use the same user namespace that is different from the host one.

https://cdn-images-1.medium.com/max/1636/1*SfAokC2YQ-f04Wc2WhSRCw.png

Although Linux allows creating user namespaces without extended privileges these namespaces only map a single user and therefore do not work with many current existing containers.
To overcome that, rootless mode has a dependency on the uidmap package that can do the remapping of users for us. The binaries in uidmap package use setuid bit (or file capabilities) and therefore always run as root internally.

To make the launching of different namespaces and integration with uidmap simpler Akihiro created a project called rootlesskit.
Rootlesskit also takes care of setting up networking for rootless containers. By default rootless docker uses networking based on moby/vpnkit project that is also used for networking in the Docker Desktop products.
Alternatively, users can install slirp4netns and use that instead.

Again:

Caveats:

Some examples of things that do not work on rootless mode are cgroups resource controls, apparmor security profiles, checkpoint/restore, overlay networks etc.
Exposing ports from containers currently requires manual socat helper process.

Only Ubuntu based distros support overlay filesystems in rootless mode.
For other systems, rootless mode uses vfs storage driver that is suboptimal in many filesystems and not recommended for production workloads.

I appreciate the OP has moved on, but here's a short answer for others. If the files /etc/subuid and /etc/subgid do not fulfill the prerequisite settings (see code below), then you will be forced to involve someone with root access.

# rightmost values returned from these commands should be >= 65536 
# if not, you're out of luck if admin doesn't like you. 
cat /etc/subgid | grep `whoami`  
cat /etc/subuid | grep `whoami`
Related