Skip to content

Instantly share code, notes, and snippets.

@mikeslattery
Last active February 23, 2022 17:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeslattery/6682698709b1fd5393eb35336e7c377c to your computer and use it in GitHub Desktop.
Save mikeslattery/6682698709b1fd5393eb35336e7c377c to your computer and use it in GitHub Desktop.
Convert local Linux distro into a container.
#!/bin/bash
# Usage - clone_to_docker.sh <image-name>
# This will convert the local distro to a container image and run it.
# Also works for WSL.
# The container will run as the user that created the image.
# If using WSL, you should mount (or symlink) /c to /mnt/c
image="wsl"
if ! docker image inspect "$image" -f '{{.ID}}' &>/dev/null; then
sudo tar -c \
--exclude /c --exclude /mnt \
--exclude /dev --exclude /proc --exclude /run --exclude /sys \
--exclude /var/cache/apt --exclude '/tmp/*' --exclude /boot --exclude /init \
--exclude /var/lib/docker \
--exclude-backups \
/ | docker import --change "ENTRYPOINT su $USER" - "$image"
fi
docker run -it --network host --privileged --tmpfs /run \
-v /var/run/docker.sock:/var/run/docker.sock \
-v wslhome:$HOME \
-v /c:/c \
-w "$PWD" "$image"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment