vps/setup-rootless.sh

27 lines
827 B
Bash
Raw Normal View History

2023-12-05 17:45:59 +01:00
#!/bin/bash
sudo apt install -y uidmap slirp4netns rootlesskit
2023-12-05 17:45:59 +01:00
if ! grep -q '/usr/share/docker.io/contrib' "$HOME/.profile" > /dev/null; then
echo 'export PATH="/usr/share/docker.io/contrib:$PATH"' >> "$HOME/.profile"
fi
if ! grep -q 'DOCKER_HOST' "$HOME/.profile" > /dev/null; then
echo "export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock" >> "$HOME/.profile"
fi
sudo loginctl enable-linger "$USER"
PATH="/usr/share/docker.io/contrib:$PATH" dockerd-rootless-setuptool.sh install
mkdir -p "$HOME/.config/systemd/user/docker.service.d"
cat << EOF > "$HOME/.config/systemd/user/docker.service.d/override.conf"
[Service]
Environment="DOCKERD_ROOTLESS_ROOTLESSKIT_NET=slirp4netns"
Environment="DOCKERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns"
EOF
systemctl --user enable docker
systemctl --user restart docker