Skip to content

Instantly share code, notes, and snippets.

@riccardobl
Last active October 1, 2019 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riccardobl/f40358b1fa15386f49c01938c7f72d55 to your computer and use it in GitHub Desktop.
Save riccardobl/f40358b1fa15386f49c01938c7f72d55 to your computer and use it in GitHub Desktop.
#!/bin/bash
############################################################
# Usage:
# vos ubuntu:18.04 bash
############################################################
# Simple script that starts a podman/docker container
# mounts the current dir, run a command as the current user
# and destroy itself when the terminal is closed
############################################################
userUID=`id -u`
groupUID=`id -g`
RUN_AS="-u=$userUID:$groupUID"
CMD=""
if [ "$2" = "" ];
then
CMD="bash";
fi
if [ "$XARGS" = "" ];
then
export XARGS=""
fi
if [ "$ROOT" != "" ];
then
export RUN_AS=""
fi
if [ "$DOCKER_IN_DOCKER" != "" ];
then
export XARGS="$XARGS -v /var/run/docker.sock:/var/run/docker.sock"
fi
RUNTIME="sudo docker"
if [ "`which podman`" != "" ];
then
RUNTIME="podman"
fi
echo $RUNTIME run $XARGS -v"$PWD:$PWD" $RUN_AS -w $PWD --rm -it $@ $CMD
$RUNTIME run $XARGS -v"$PWD:$PWD" $RUN_AS -w $PWD --rm -it $@ $CMD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment