Last active
February 23, 2022 17:24
-
-
Save mikeslattery/6682698709b1fd5393eb35336e7c377c to your computer and use it in GitHub Desktop.
Convert local Linux distro into a container.
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
#!/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