Skip to content

Commit

Permalink
adds Docker outside of Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalan committed Jan 28, 2024
1 parent 5797503 commit 1bdf373
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
12 changes: 4 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 41 additions & 0 deletions etc/init.d/docker
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1bdf373

Please sign in to comment.