There’s a neat script that I’ve made for developing image:
#!/bin/bash
# Made by Lauri Jakku <lja@lja.fi>
tmp=/tmp/docker-run-image.$$
errcheck() {
if [ $1 -eq 0 ]
then
return
else
shift
echo $*
exit 1
fi
}
# WARNING: THIS WILL CLEAN EVERY IMAGE in system (local ones)!
echo "Cleaning up the system ..................."
docker ps | grep -v "IMAGE.*CREATED" | awk '{ print "docker rm --force " $1 }' | sh
echo "Building ..................."
docker buildx build --network=host --iidfile=$tmp.imghash .
errcheck $? "Docker build error"
IMGHASH=$(cat $tmp.imghash| sed 's,sha256:\(............\).*,\1,')
CNTNAME="the-image-container-of-$IMGHASH"
echo "Built $IMGHASH ..................."
docker create --init --privileged --network="host" --name="$CNTNAME" $IMGHASH
errcheck $? "Docker Create error"
# Check container id
CNTID=$(docker ps -a | grep $IMGHASH | head -1 | awk '{ print $1 }')
echo "Running container $CNTID (Made from image $IMGHASH) ..................."
docker start $CNTID
errcheck $? "Docker start $CNTID error"
echo "To exceute command in container:"
echo " docker exec -it --privileged $CNTID <command>"
The script will rebuild the project in current working directory and run it in container and provide command to run command(s) inside the container.
WARNING:
The script will (if not modified) delete ALL images within the docker.
YOU HAVE BEEN WARNED, I take no responsibility what so ever from
possible dataloss or what ever, while using the script.
There you go… happy hacking …