Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if container is running in privileged mode before starting dind #251

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions devcontainer/rootfs/etc/s6-overlay/s6-rc.d/dind/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# 111 is a signal from ./run
if [[ "${1}" -eq 111 ]]; then
# 125 indicates a permanent failure to s6-overlay, which aborts the startup
exit 125
fi
6 changes: 6 additions & 0 deletions devcontainer/rootfs/etc/s6-overlay/s6-rc.d/dind/run
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ if grep -qw sysboxfs /proc/self/mountinfo; then
exec "${@}" dockerd
fi

if ! /opt/docker-scripts/is_privileged.sh; then
echo "[dind] the container must be running in privileged mode for dind to work" >&2
# an arbitrary exit code, used as a signal to ./finish to abort the startup
exit 111
fi

# the sleep helps workaround the "sed: couldn't flush stdout: Device or resource busy"
# error on first startup attempt
exec "${@}" bash -c 'sleep 0.5s && exec dind dockerd'
16 changes: 6 additions & 10 deletions devcontainer/scripts/prepare_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,12 @@ ${CURL} "https://github.com/felipecrs/docker-on-docker-shim/raw/v${DOND_SHIM_VER
-o /usr/local/bin/dond
chmod +x /usr/local/bin/dond

# install cgroup-scripts
# renovate: datasource=github-releases depName=felipecrs/cgroup-scripts
CGROUP_SCRIPTS_VERSION="0.2.0"
mkdir -p /opt/cgroup-scripts
${CURL} "https://github.com/felipecrs/cgroup-scripts/raw/v${CGROUP_SCRIPTS_VERSION}/get_cpus.sh" \
-o /opt/cgroup-scripts/get_cpus.sh
chmod +x /opt/cgroup-scripts/get_cpus.sh
${CURL} "https://github.com/felipecrs/cgroup-scripts/raw/v${CGROUP_SCRIPTS_VERSION}/get_memory.sh" \
-o /opt/cgroup-scripts/get_memory.sh
chmod +x /opt/cgroup-scripts/get_memory.sh
# install docker-scripts
# renovate: datasource=github-releases depName=felipecrs/docker-scripts
DOCKER_SCRIPTS_VERSION="0.2.0"
mkdir -p /opt/docker-scripts
${CURL} "https://github.com/felipecrs/docker-scripts/archive/v${DOCKER_SCRIPTS_VERSION}.tar.gz" |
tar -C /opt/docker-scripts --strip-components=2 -xzf - --wildcards "docker-scripts-*/scripts"

# setup oh my bash, useful when debugging the container
${CURL} https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh |
Expand Down