Skip to content

Instantly share code, notes, and snippets.

@fo40225
Last active October 29, 2024 03:06
Show Gist options
  • Save fo40225/68a0f573c6ae3176e9702733f900e06c to your computer and use it in GitHub Desktop.
Save fo40225/68a0f573c6ae3176e9702733f900e06c to your computer and use it in GitHub Desktop.
docker, systemd in container
# cgroups v1 (ubuntu <=20.04)
sudo docker run --name centos-1 --restart unless-stopped -i -t -d -p 2222:22 --privileged --stop-signal SIGRTMIN+3 --entrypoint /usr/sbin/init --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /var/run/docker.sock:/var/run/docker.sock centos:7.9.2009
sudo docker run --name ubuntu-1 --restart unless-stopped -i -t -d -p 2222:22 --privileged --stop-signal SIGRTMIN+3 --entrypoint /sbin/init --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /var/run/docker.sock:/var/run/docker.sock ubuntu:16.04
sudo docker run --name debian-1 --restart unless-stopped -i -t -d -p 2222:22 --privileged --stop-signal SIGRTMIN+3 --entrypoint /sbin/init --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /var/run/docker.sock:/var/run/docker.sock debian:8.11
# cgroups v2 (ubuntu >=22.04)
sudo docker run --name rhel-1 --restart unless-stopped -i -t -d -p 2222:22 --privileged -v /var/run/docker.sock:/var/run/docker.sock redhat/ubi8-init:8.10
sudo docker run --name rhel-1 --restart unless-stopped -i -t -d -p 2222:22 --privileged -v /var/run/docker.sock:/var/run/docker.sock redhat/ubi9-init:9.4
mkdir ubuntu-init
cd ubuntu-init
echo 'FROM ubuntu:22.04' >>Dockerfile
echo 'RUN apt update && apt install -y init' >>Dockerfile
sudo docker build -t ubuntu:22.04-init .
sudo docker run --name ubuntu-1 --restart unless-stopped -i -t -d -p 2222:22 --privileged --stop-signal SIGRTMIN+3 --entrypoint /sbin/init --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup -v /var/run/docker.sock:/var/run/docker.sock ubuntu:22.04-init
sudo docker exec -i -t ubuntu-1 bash
sed -i 's/archive.ubuntu.com/tw.archive.ubuntu.com/g' /etc/apt/sources.list
apt update
apt install -y sudo openssh-server curl
adduser user
adduser user sudo
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
groupadd docker
usermod -aG docker user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment