Skip to content

Instantly share code, notes, and snippets.

@mikeslattery
Last active January 13, 2022 16:51
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/7c74daf7fcdb4cafb0eba71f768cf5ba to your computer and use it in GitHub Desktop.
Save mikeslattery/7c74daf7fcdb4cafb0eba71f768cf5ba to your computer and use it in GitHub Desktop.
Run containers as if they are locally installed tools
#!/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" "$@"
@mikeslattery
Copy link
Author

mikeslattery commented Jan 2, 2019

  • To add ability to run docker commands: -v /var/run/docker.sock:/var/run/docker.sock \
  • If run from inside a container, to inherit mounts: --volumes-from $(hostname) \

@mikeslattery
Copy link
Author

Fyi, X11 apps should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment