================ LXD Containers ================ .. code-block:: sh # For understanding LXC see https://wiki.debian.org/LXC # Based on: # lxd + docker: https://stgraber.org/2016/04/13/lxd-2-0-docker-in-lxd-712/ # lxd network (static ip): https://stgraber.org/2016/10/27/network-management-with-lxd-2-3/ LXD_NETWORK="dev-network2" # install lxd 2.3+ apt-get install software-properties-common iptables-persistent add-apt-repository ppa:ubuntu-lxc/lxd-stable apt-get update apt-get dist-upgrade apt-get install lxd # init lxd lxd init # init network lxc network create ${LXD_NETWORK} lxc network show ${LXD_NETWORK} # check ipv4.address field ############################ # Per each Developer GITHUB_USERNAME="yelizariev" CONTAINER="${GITHUB_USERNAME}" SERVER_DOMAIN="${GITHUB_USERNAME}.dev.it-projects.info" NGINX_CONF="dev-${GITHUB_USERNAME}.conf" LOCAL_IP="10.37.82.100" # use one from network subnet PORT="10100" # unique per each developer # https://discuss.linuxcontainers.org/t/docker-cannot-write-to-devices-allow/998/3 read -r -d '' RAW_LXC <> /root/.ssh/authorized_keys" && \ # access for noroot lxc exec ${CONTAINER} -- bash -c "echo $PASS > /root/noroot-password" && \ lxc exec ${CONTAINER} -- bash -c "echo noroot:$PASS | chpasswd " && \ lxc exec ${CONTAINER} -- sudo -u "noroot" bash -c "mkdir -p /home/noroot/.ssh" && \ lxc exec ${CONTAINER} -- sudo -u "noroot" bash -c "curl --silent https://github.com/${GITHUB_USERNAME}.keys >> /home/noroot/.ssh/authorized_keys" && \ lxc exec ${CONTAINER} -- sudo -u "noroot" sed -i "s/01;32m/01;93m/" /home/noroot/.bashrc && \ # Manage Docker as a non-root user https://docs.docker.com/install/linux/linux-postinstall/ lxc exec ${CONTAINER} -- usermod -aG docker noroot && \ lxc exec ${CONTAINER} -- usermod -aG sudo noroot && \ lxc exec ${CONTAINER} -- locale-gen --purge en_US.UTF-8 && \ lxc exec ${CONTAINER} -- bash -c "echo -e 'LANG=\"en_US.UTF-8\"\nLANGUAGE=\"en_US:en\"\n' > /etc/default/locale" lxc config device add ${CONTAINER} sharedcachenoroot disk path=/home/noroot/.cache source=/var/lxc/share/cache && \ lxc stop ${CONTAINER} && \ lxc start ${CONTAINER} ## nginx on host machine cd /tmp/ curl -s https://gitlab.com/itpp/odoo-devops/raw/master/docs/remote-dev/lxd/nginx.conf > nginx.conf sed -i "s/NGINX_SERVER_DOMAIN/.${SERVER_DOMAIN}/g" nginx.conf sed -i "s/SERVER_HOST/${LOCAL_IP}/g" nginx.conf cp nginx.conf /etc/nginx/sites-available/${NGINX_CONF} ln -s /etc/nginx/sites-available/${NGINX_CONF} /etc/nginx/sites-enabled/${NGINX_CONF} # then restart nginx in a usual way ################### # Control commands # delete container lxc delete CONTAINER-NAME # see iptables rules iptables -L -t nat # delete nat rule iptables -t nat -D PREROUTING POSITION_NUMBER