Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ -z "$1" ] | ||
then | ||
echo "The run-docker-station script takes a command as a argument. E.g., try ./run-docker-station 'ls' " | ||
exit 1 | ||
fi | ||
|
||
set -o noglob | ||
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" | ||
|
||
COMMAND=$@ | ||
|
||
|
||
|
||
container_name=${CONTAINER_NAME:-"programming_station-for-$USER"} | ||
|
||
command -v docker >/dev/null 2>&1 || { echo >&2 "Please install docker. E.g., go to https://www.docker.com/products/docker-desktop Type 'docker' to diagnose the problem."; exit 1; } | ||
|
||
docker info >/dev/null 2>&1 || { echo >&2 "Docker server is not running? type 'docker info'."; exit 1; } | ||
|
||
SSHPARAM="" | ||
[ -e "${SSH_AUTH_SOCK}" ] && SSHPARAM="--volume /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock --env SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock" | ||
[ -e "${HOME}/.ssh" ] && SSHPARAM="--volume ${HOME}/.ssh:/home/$USER/.ssh:ro" | ||
|
||
|
||
docker image inspect $container_name >/dev/null 2>&1 || ( echo "instantiating the container" ; docker build --no-cache -t $container_name -f $SCRIPTPATH/Dockerfile --build-arg USER_NAME="$USER" --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) . ) | ||
|
||
# We run in privileged mode to have access to performance counters. | ||
if [ -t 0 ]; then DOCKER_ARGS=-it; fi | ||
docker run --rm $DOCKER_ARGS -h $container_name --privileged $SSHPARAM -v $(pwd):$(pwd):Z -w $(pwd) $container_name sh -c "$COMMAND" | ||
|
||
|
||
|