2019-01-09 20:50:47 -05:00
|
|
|
#!/bin/sh
|
2014-04-29 01:13:25 -04:00
|
|
|
set -e
|
2013-09-06 22:02:59 -04:00
|
|
|
|
2013-09-06 22:03:29 -04:00
|
|
|
# DinD: a wrapper script which allows docker to be run inside a docker container.
|
2014-07-24 18:19:50 -04:00
|
|
|
# Original version by Jerome Petazzoni <jerome@docker.com>
|
2015-04-11 13:22:16 -04:00
|
|
|
# See the blog post: https://blog.docker.com/2013/09/docker-can-now-run-within-docker/
|
2013-09-06 22:03:29 -04:00
|
|
|
#
|
2016-05-24 23:38:28 -04:00
|
|
|
# This script should be executed inside a docker container in privileged mode
|
2014-03-13 13:46:02 -04:00
|
|
|
# ('docker run --privileged', introduced in docker 0.6).
|
2013-09-06 22:03:29 -04:00
|
|
|
|
|
|
|
# Usage: dind CMD [ARG...]
|
|
|
|
|
2014-05-01 17:52:29 -04:00
|
|
|
# apparmor sucks and Docker needs to know that it's in a container (c) @tianon
|
|
|
|
export container=docker
|
|
|
|
|
2019-01-09 20:23:38 -05:00
|
|
|
if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then
|
2014-04-29 01:13:25 -04:00
|
|
|
mount -t securityfs none /sys/kernel/security || {
|
|
|
|
echo >&2 'Could not mount /sys/kernel/security.'
|
2015-10-12 01:46:14 -04:00
|
|
|
echo >&2 'AppArmor detection and --privileged mode might break.'
|
2014-04-29 01:13:25 -04:00
|
|
|
}
|
2013-10-31 17:58:43 -04:00
|
|
|
fi
|
|
|
|
|
2015-08-21 18:47:50 -04:00
|
|
|
# Mount /tmp (conditionally)
|
|
|
|
if ! mountpoint -q /tmp; then
|
|
|
|
mount -t tmpfs none /tmp
|
|
|
|
fi
|
2013-09-06 22:19:03 -04:00
|
|
|
|
2020-06-03 09:37:14 -04:00
|
|
|
# cgroup v2: enable nesting
|
|
|
|
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
|
|
|
|
# move the init process (PID 1) from the root group to the /init group,
|
|
|
|
# otherwise writing subtree_control fails with EBUSY.
|
|
|
|
mkdir -p /sys/fs/cgroup/init
|
|
|
|
echo 1 > /sys/fs/cgroup/init/cgroup.procs
|
|
|
|
# enable controllers
|
|
|
|
sed -e 's/ / +/g' -e 's/^/+/' < /sys/fs/cgroup/cgroup.controllers \
|
|
|
|
> /sys/fs/cgroup/cgroup.subtree_control
|
|
|
|
fi
|
|
|
|
|
2019-01-09 20:23:38 -05:00
|
|
|
if [ $# -gt 0 ]; then
|
2014-04-29 01:13:25 -04:00
|
|
|
exec "$@"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo >&2 'ERROR: No command specified.'
|
|
|
|
echo >&2 'You probably want to run hack/make.sh, or maybe a shell?'
|