vpsmusthave/docker-rootless.sh

52 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2024-07-22 11:43:08 +02:00
#!/bin/bash
source ./variables
echo "Please confirm installing dependencies"
apt update
apt install ca-certificates curl
echo "Installing docker..."
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/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/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
echo "Installing docker now, please confirm"
apt update
apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin dbus-user-session fuse-overlayfs uidmap iptables
systemctl disable --now docker.service docker.socket
rm /var/run/docker.sock
echo "Installing for user $DOCKER_USER..."
useradd -m -s /bin/bash -G docker $DOCKER_USER
loginctl enable-linger $DOCKER_USER
USER_UID=$(id -u $DOCKER_USER)
cat <<EOF >> /home/$DOCKER_USER/.profile
export XDG_RUNTIME_DIR=/run/user/$USER_UID
export DOCKER_HOST=unix://\$XDG_RUNTIME_DIR/docker.sock
EOF
echo "Waiting for systemd..."
until sudo -iu $DOCKER_USER systemctl --user show-environment &> /dev/null; do
sleep .1
done
sudo -iu $DOCKER_USER /usr/bin/dockerd-rootless-setuptool.sh install
sudo -iu $DOCKER_USER docker run hello-world
echo
echo "To manage docker, do:"
echo " sudo -iu $DOCKER_USER"
echo "Or execute commands directly (not recommended):"
echo " sudo -iu $DOCKER_USER docker run hello-world"
echo