Skip to content

Instantly share code, notes, and snippets.

@nailgun
Created January 8, 2015 04:01
Show Gist options
  • Save nailgun/98b334cdebe7efe9e355 to your computer and use it in GitHub Desktop.
Save nailgun/98b334cdebe7efe9e355 to your computer and use it in GitHub Desktop.
CoreOS Toolbox by DigitalOcean
#!/bin/bash
TOOLBOX_DOCKER_IMAGE=fedora
TOOLBOX_DOCKER_TAG=latest
TOOLBOX_USER=root
toolboxrc="${HOME}"/.toolboxrc
if [ -f "${toolboxrc}" ]; then
source "${toolboxrc}"
fi
machinename=$(echo "${USER}-${TOOLBOX_DOCKER_IMAGE}-${TOOLBOX_DOCKER_TAG}" | sed -r 's/[^a-zA-Z0-9_.-]/_/g')
machinepath="/var/lib/toolbox/${machinename}"
osrelease="${machinepath}/etc/os-release"
if [ ! -f ${osrelease} ] || systemctl is-failed -q ${machinename} ; then
sudo mkdir -p "${machinepath}"
sudo chown ${USER}: "${machinepath}"
docker pull "${TOOLBOX_DOCKER_IMAGE}:${TOOLBOX_DOCKER_TAG}"
docker run --name=${machinename} "${TOOLBOX_DOCKER_IMAGE}:${TOOLBOX_DOCKER_TAG}" /bin/true
docker export ${machinename} | sudo tar -x -C "${machinepath}" -f -
docker rm ${machinename}
sudo touch ${osrelease}
fi
sudo systemd-nspawn -D "${machinepath}" --share-system --bind=/:/media/root --bind=/usr:/media/root/usr --user="${TOOLBOX_USER}" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment