2019-01-10 02:50:47 +01:00
|
|
|
#!/bin/sh
|
2014-04-28 23:13:25 -06:00
|
|
|
set -e
|
2013-09-06 19:02:59 -07:00
|
|
|
|
2013-09-06 19:03:29 -07:00
|
|
|
# DinD: a wrapper script which allows docker to be run inside a docker container.
|
2014-07-24 22:19:50 +00: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 19:03:29 -07:00
|
|
|
#
|
2016-05-24 20:38:28 -07:00
|
|
|
# This script should be executed inside a docker container in privileged mode
|
2014-03-13 11:46:02 -06:00
|
|
|
# ('docker run --privileged', introduced in docker 0.6).
|
2013-09-06 19:03:29 -07:00
|
|
|
|
|
|
|
# Usage: dind CMD [ARG...]
|
|
|
|
|
2014-05-01 21:52:29 +00:00
|
|
|
# apparmor sucks and Docker needs to know that it's in a container (c) @tianon
|
|
|
|
export container=docker
|
|
|
|
|
2019-01-10 02:23:38 +01:00
|
|
|
if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then
|
2014-04-28 23:13:25 -06:00
|
|
|
mount -t securityfs none /sys/kernel/security || {
|
|
|
|
echo >&2 'Could not mount /sys/kernel/security.'
|
2015-10-11 22:46:14 -07:00
|
|
|
echo >&2 'AppArmor detection and --privileged mode might break.'
|
2014-04-28 23:13:25 -06:00
|
|
|
}
|
2013-10-31 14:58:43 -07:00
|
|
|
fi
|
|
|
|
|
2015-08-21 15:47:50 -07:00
|
|
|
# Mount /tmp (conditionally)
|
|
|
|
if ! mountpoint -q /tmp; then
|
|
|
|
mount -t tmpfs none /tmp
|
|
|
|
fi
|
2013-09-06 19:19:03 -07:00
|
|
|
|
2020-06-03 22:37:14 +09: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-10 02:23:38 +01:00
|
|
|
if [ $# -gt 0 ]; then
|
2014-04-28 23:13:25 -06:00
|
|
|
exec "$@"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo >&2 'ERROR: No command specified.'
|
|
|
|
echo >&2 'You probably want to run hack/make.sh, or maybe a shell?'
|