Last active
January 13, 2022 16:51
-
-
Save mikeslattery/7c74daf7fcdb4cafb0eba71f768cf5ba to your computer and use it in GitHub Desktop.
Run containers as if they are locally installed tools
This file contains hidden or 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 | |
# Run containers as if they are locally installed tools. | |
# This is useful for images such as "python" or "maven". | |
# Edit the "image" variable and place in your ~/bin directory. | |
# For "Docker Desktop for Windows" under these environments: | |
# * WSL: if /c is mounted to C: and run from a dir under /c, but /tmp and $HOME volumes should be removed. | |
# * Msys/GitBash: but /tmp volume should be removed. | |
# * Cygwin: Will not work as-is due to path differences. | |
image='<image-name>' | |
id=$(docker create \ | |
--env-file <(export -p) \ | |
-e "DISPLAY=${DISPLAY:-$HOSTNAME:0}" \ | |
-v "$HOME:$HOME" \ | |
-v "$PWD:$PWD" \ | |
-v "/tmp:/tmp" \ | |
-u "$(id -u):$(id -g)" \ | |
$(id -G | xargs -rL1 -d' ' echo --group-add) \ | |
-w "$PWD" \ | |
--network host \ | |
$DOCKER_RUN_OPTS \ | |
-d -t --rm "$image") | |
docker cp /etc/passwd "$id:/etc/passwd" | |
docker cp /etc/group "$id:/etc/group" | |
docker start -i "$id" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fyi, X11 apps should work.