Add Docker in Docker

This commit is contained in:
Josh.5
2022-10-08 21:01:08 +13:00
committed by Josh Sunnex
parent 477e25f82c
commit 9712eede91
12 changed files with 151 additions and 14 deletions

View File

@@ -9,24 +9,52 @@
# Modified By: Josh.5 (jsunnex@gmail.com)
###
# Wait for X server to start
# (Credit: https://gist.github.com/tullmann/476cc71169295d5c3fe6)
wait_for_x() {
# Wait for X server to start
# (Credit: https://gist.github.com/tullmann/476cc71169295d5c3fe6)
MAX=60 # About 30 seconds
CT=0
while ! xdpyinfo >/dev/null 2>&1; do
sleep 0.50s
CT=$(( CT + 1 ))
if [ "$CT" -ge "$MAX" ]; then
LOG "FATAL: $0: Gave up waiting for X server $DISPLAY"
echo "FATAL: $0: Gave up waiting for X server $DISPLAY"
exit 11
fi
done
}
# Wait for udev init to complete
wait_for_udev() {
MAX=10
CT=0
while [ ! -f /tmp/.udev-started ]; do
sleep 1
CT=$(( CT + 1 ))
if [ "$CT" -ge "$MAX" ]; then
echo "FATAL: $0: Gave up waiting for udev server to start"
exit 11
fi
done
}
# Wait for dockerd to start
wait_for_docker() {
MAX=10
CT=0
while ! docker system info >/dev/null 2>&1; do
sleep 1
CT=$(( CT + 1 ))
if [ "$CT" -ge "$MAX" ]; then
echo "FATAL: $0: Gave up waiting for dockerd service to start"
exit 11
fi
done
echo "DOCKERD RUNNING!"
}
# Fech NVIDIA GPU device (if one exists)
get_nvidia_gpu_id() {
# Fech NVIDIA GPU device (if one exists)
if [ "${NVIDIA_VISIBLE_DEVICES:-}" == "all" ]; then
gpu_select=$(nvidia-smi --format=csv --query-gpu=uuid 2> /dev/null | sed -n 2p)
elif [ -z "${NVIDIA_VISIBLE_DEVICES:-}" ]; then

View File

@@ -8,7 +8,7 @@
# Last Modified: Wednesday, 26th January 2022 5:38:23 pm
# Modified By: Console and webGui login account (jsunnex@gmail.com)
###
set -e
source /usr/bin/common-functions.sh
# CATCH TERM SIGNAL:
@@ -22,10 +22,6 @@ trap _term SIGTERM SIGINT
XDG_DATA_DIRS="${XDG_DATA_DIRS}:/var/lib/flatpak/exports/share:/home/${USER}/.local/share/flatpak/exports/share"
export $(dbus-launch)
# Set the default background for gnome based desktop
mkdir -p /etc/alternatives
ln -sf /usr/share/backgrounds/steam.jpg /etc/alternatives/desktop-background
# EXECUTE PROCESS:
# Wait for the X server to start

52
overlay/usr/bin/start-dind.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/env bash
###
# File: start-dind.sh
# Project: bin
# File Created: Saturday, 8th October 2022 1:49:45 pm
# Author: Josh.5 (jsunnex@gmail.com)
# -----
# Last Modified: Saturday, 8th October 2022 1:49:45 pm
# Modified By: Josh.5 (jsunnex@gmail.com)
###
set -e
# CATCH TERM SIGNAL:
_term() {
kill -TERM "$docker_pid" 2>/dev/null
}
trap _term SIGTERM SIGINT
# CONFIGURE:
# Refrences:
# - https://raw.githubusercontent.com/docker/docker/42b1175eda071c0e9121e1d64345928384a93df1/hack/dind
#
# apparmor sucks and Docker needs to know that it's in a container (c) @tianon
export container=docker
if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then
mount -t securityfs none /sys/kernel/security || {
echo >&2 'Could not mount /sys/kernel/security.'
echo >&2 'AppArmor detection and --privileged mode might break.'
}
fi
# cgroup v2: enable nesting
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
# move the processes from the root group to the /init group,
# otherwise writing subtree_control fails with EBUSY.
# An error during moving non-existent process (i.e., "cat") is ignored.
mkdir -p /sys/fs/cgroup/init
xargs -rn1 < /sys/fs/cgroup/cgroup.procs > /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
# EXECUTE PROCESS:
/usr/local/bin/dockerd &
docker_pid=$!
# WAIT FOR CHILD PROCESS:
wait "$docker_pid"

View File

@@ -8,6 +8,7 @@
# Last Modified: Sunday, 2nd October 2022 22:58:17 pm
# Modified By: Josh.5 (jsunnex@gmail.com)
###
set -e
# CATCH TERM SIGNAL:
_term() {

View File

@@ -8,7 +8,7 @@
# Last Modified: Tuesday, 4th October 2022 8:22:17 pm
# Modified By: Josh.5 (jsunnex@gmail.com)
###
set -e
source /usr/bin/common-functions.sh
# CATCH TERM SIGNAL:

View File

@@ -8,6 +8,7 @@
# Last Modified: Friday, 14th January 2022 9:21:00 am
# Modified By: Josh.5 (jsunnex@gmail.com)
###
set -e
# CATCH TERM SIGNAL:
_term() {

View File

@@ -8,7 +8,7 @@
# Last Modified: Tuesday, 6th October 2022 9:30:00 pm
# Modified By: Josh.5 (jsunnex@gmail.com)
###
set -e
source /usr/bin/common-functions.sh
# CATCH TERM SIGNAL:

View File

@@ -8,6 +8,7 @@
# Last Modified: Friday, 6th October 2022 9:21:00 pm
# Modified By: Josh.5 (jsunnex@gmail.com)
###
set -e
# CATCH TERM SIGNAL:
_term() {