Skip to content

Instantly share code, notes, and snippets.

@mwiget
Created February 22, 2018 08:17
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 mwiget/5696711d693eeb43506bcb92cbfc1777 to your computer and use it in GitHub Desktop.
Save mwiget/5696711d693eeb43506bcb92cbfc1777 to your computer and use it in GitHub Desktop.
Launch Docker containers like native apps with current directory (rw) mounted
#!/bin/sh
name=$(basename $0)
if [ $name == "launch-docker-container" ]; then
cat <<EOF
$0
please link this script to the container image you like to run
e.g. to launch latest alpine image with the current working directory mounted:
$ ln -s launch-docker-container.sh alpine
$ ./alpine
/u # ls
alpine launch-docker-container.sh
/u # uname -a
Linux 68b18fa5b4d4 4.9.75-linuxkit-aufs #1 SMP Tue Jan 9 10:58:17 UTC 2018 x86_64 Linux
/u # exit
It also accept arguments:
$ alpine uname -a
Linux 3b18ba5282f3 4.9.75-linuxkit-aufs #1 SMP Tue Jan 9 10:58:17 UTC 2018 x86_64 Linux
$
EOF
exit 1
fi
img=$(docker images -q $name)
if [ -z "$img" ]; then
echo "docker image $name doesn't exist"
fi
exec docker run -ti --rm -v ${PWD}:/u --workdir /u $name $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment