diff --git a/Dockerfile b/Dockerfile index 18df9ec..df7cbd5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -227,19 +227,16 @@ RUN curl https://packagecloud.io/install/repositories/cs50/repo/script.deb.sh | RUN apt update && \ apt install --no-install-recommends --no-install-suggests --yes \ ca-certificates \ - curl && \ + curl \ + socat && \ install -d /etc/apt/keyrings -m 0755 && \ curl --fail --location --show-error --silent https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \ chmod a+r /etc/apt/keyrings/docker.asc && \ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \ apt update && \ sudo apt install --no-install-recommends --no-install-suggests --yes \ - containerd.io \ - docker-buildx-plugin \ - docker-ce \ - docker-ce-cli \ - docker-compose-plugin && \ - groupadd --force docker + docker-ce-cli && \ + groupadd docker # Install Python packages @@ -293,7 +290,6 @@ ONBUILD ARG VCS_REF ONBUILD RUN echo "$VCS_REF" >> /etc/issue ONBUILD USER ubuntu - # Set user USER ubuntu WORKDIR /home/ubuntu diff --git a/Makefile b/Makefile index a996d28..1520b8f 100644 --- a/Makefile +++ b/Makefile @@ -3,19 +3,15 @@ default: run build: docker build --build-arg VCS_REF="$(shell git rev-parse HEAD)" --tag cs50/cli . - $(MAKE) squash depends: pip3 install docker-squash rebuild: docker build --no-cache --tag cs50/cli . - $(MAKE) squash run: - docker run --env LANG="$(LANG)" --interactive --privileged --publish-all --rm --security-opt seccomp=unconfined --tty --volume "$(PWD)":/home/ubuntu cs50/cli bash --login || true + docker run --env LANG="$(LANG)" --interactive --publish-all --rm --security-opt seccomp=unconfined --tty --volume "$(PWD)":/home/ubuntu --volume /var/run/docker.sock:/var/run/docker-host.sock cs50/cli bash --login || true squash: depends - docker images cs50/cli docker-squash --tag cs50/cli cs50/cli - docker images cs50/cli diff --git a/etc/init.d/docker b/etc/init.d/docker new file mode 100755 index 0000000..047c89f --- /dev/null +++ b/etc/init.d/docker @@ -0,0 +1,41 @@ +#!/bin/bash + +# Adapted from https://github.com/devcontainers/features/blob/main/src/docker-outside-of-docker/install.sh. +# If docker-ce is installed, shadows its own. + +set -e + +SOURCE_SOCKET=/var/run/docker-host.sock +TARGET_SOCKET=/var/run/docker.sock +SOCAT_PID=/tmp/docker.pid + +case "$1" in + start) + echo "Starting Docker" + socat UNIX-LISTEN:${TARGET_SOCKET},fork,mode=660,group=docker UNIX-CONNECT:${SOURCE_SOCKET} & echo "$!" > "$SOCAT_PID" + ;; + stop) + echo "Stopping Docker" + kill -9 $(cat "$SOCAT_PID") 2> /dev/null + rm --force "$SOCAT_PID" "$TARGET_SOCKET" + ;; + restart) + $0 stop + $0 start + ;; + status) + if [[ ! -f "${SOCAT_PID}" ]] || ! ps -p $(cat "$SOCAT_PID") > /dev/null; then + echo "Docker is not running" + exit 1 + else + echo "Docker is running" + exit 0 + fi + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0