A script for running commands in the docker container

This commit is contained in:
thomas committed 2018-03-19 20:29:39 +01:00
1 parent e30ed2ae56
commit 9daacb1402
1 file changed
+30
Executable
+30
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