Skip to content

Instantly share code, notes, and snippets.

@cyberbit
Last active August 14, 2020 20:54
Show Gist options
  • Save cyberbit/addcd7fa2500977ac5b4248ebe124898 to your computer and use it in GitHub Desktop.
Save cyberbit/addcd7fa2500977ac5b4248ebe124898 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Launch a bash session in your docker workspace, from a specified starting directory.
#
# Usage: larabash [workdir]
# workdir: path to starting root directory (defaults to name of current directory)
######################################################################################
# Parent directory of project on host machine
# for example, project is at /path/to/project/parent/project
HOSTROOT="/path/to/project/parent"
# Parent directory of project volume in container
# for example, project mounts to /var/www/project
CONTAINERROOT="/var/www"
# the magic :O
HOSTPWD=${PWD/$HOSTROOT\//}
WORKDIR=${1:-${HOSTPWD}}
# Replace with your host root project path
cd $HOSTROOT/project
# Replace with your launch command of choice, important part is --workdir
docker-compose exec --workdir="$CONTAINERROOT/$WORKDIR" container-name bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment