Skip to content

Instantly share code, notes, and snippets.

@AkihiroSuda
Created October 15, 2018 08:16
Show Gist options
  • Save AkihiroSuda/772604c6895d5ced5357e5dcc154be22 to your computer and use it in GitHub Desktop.
Save AkihiroSuda/772604c6895d5ced5357e5dcc154be22 to your computer and use it in GitHub Desktop.
Create nightly Docker-in-LXD environment
#!/bin/bash
# Create Docker-in-LXD environment
set -exu -o pipefail
if [[ $# -ne 1 ]]; then
echo "Usage: $0 NAME"
exit 1
fi
CONTAINER=$1
POOL=pool-dir
IMAGE=ubuntu:18.04
# Create pool if not created yet
# We use "dir" driver. /var/lib/lxd/storage-pools on the host needs to be ext4 or xfs.
lxc storage show $POOL > /dev/null 2>&1 || lxc storage create $POOL dir
# Remove existing container if any
lxc info $CONTAINER > /dev/null 2>&1 && lxc rm -f $CONTAINER
# Create container
lxc launch $IMAGE $CONTAINER -s $POOL -c security.nesting=true
# Cargo-cult sleep for networking (FIXME)
sleep 10
# Execute the script
cat <<EOF | lxc exec $CONTAINER -- sh -exu
for f in dockerd containerd containerd-shim ctr runc docker-init docker-proxy docker;do
curl -o /usr/bin/\$f https://master.dockerproject.org/linux/x86_64/\$f
chmod +x /usr/bin/\$f
done
groupadd docker
for f in docker.socket docker.service; do
curl -o /lib/systemd/system/\$f https://raw.githubusercontent.com/moby/moby/master/contrib/init/systemd/\$f
done
systemctl daemon-reload
systemctl enable docker
systemctl start docker
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment