A script for running commands in the docker container

This commit is contained in:
Thomas Lovén 2017-10-23 21:25:22 +02:00
parent e30ed2ae56
commit 9daacb1402

30
d Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env bash
imagename=mittos64
buildroot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
# Check if the docker image exists
# If not, ask if it should be built
if ! docker image ls -f reference=${imagename} | grep ${imagename} >/dev/null; then
echo "Docker image does not exist."
echo "Do you wish to build it? (This could take a while)"
read -r -p "[y/N]: " response
case "$response" in
[Yy][Ee][Ss]|[Yy])
docker build -t ${imagename} ${buildroot}/toolchain
;;
*)
exit
;;
esac
fi
# Check if a container is already running the image
# If so, execute the command in the running container
if docker ps -f name=${imagename}-run | grep ${imagename}-run ; then
docker exec -it ${imagename}-run "$@"
else
docker run -it --rm -v ${buildroot}:/opt --name ${imagename}-run ${imagename} "$@"
fi