Created
July 3, 2019 09:20
-
-
Save egeneralov/5edbb3305fb893b130eaa0f90163ec99 to your computer and use it in GitHub Desktop.
Just note for juniors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# variables for run | |
NAME=cloudflare.com | |
SRCIP=1.1.1.1 | |
# delete droplet | |
doctl compute droplet delete "${NAME}" --force | |
# create new droplet | |
doctl compute droplet create \ | |
"${NAME}" \ | |
--size 1gb \ | |
--image debian-9-x64 \ | |
--region fra1 \ | |
--ssh-keys 98:72:1e:a6:f5:4c:92:b0:92:67:7c:f4:11:2c:19:e5 \ | |
--enable-backups \ | |
--wait | |
# go to machine | |
doctl compute ssh "${NAME}" | |
# install lxc | |
apt-get update -q | |
apt-get install -yq lxc xz-utils dnsmasq-base | |
# generate ssh key, install to ${SRCIP} | |
ssh-keygen | |
cat ~/.ssh/id_rsa.pub | |
# create lxc container | |
lxc-create -t download -n "${NAME}" -- -d debian -r stretch -a amd64 --no-validate | |
# rewrite configuration (networking) | |
cat << EOF > "/var/lib/lxc/${NAME}/config" | |
lxc.include = /usr/share/lxc/config/debian.common.conf | |
lxc.arch = linux64 | |
lxc.rootfs = /var/lib/lxc/"${NAME}"/rootfs | |
lxc.rootfs.backend = dir | |
lxc.utsname = "${NAME}" | |
lxc.network.type = none | |
EOF | |
# sync remote machine to lxc container | |
screen rsync -vzaAX \ | |
--progress \ | |
--numeric-ids \ | |
--delete \ | |
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","etc/network/interfaces"} \ | |
${SRCIP}:/ /var/lib/lxc/"${NAME}"/rootfs/ | |
# start container | |
lxc-start -n "${NAME}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment