I am a beginner to Docker and was trying to optimize the following bash shell code. The below code continuously has to create a docker container and remove it. What I would like is a one-time creation of the docker container; then based on the if-else condition, the corresponding command gets iteratively executed in while loop and finally, the docker container gets deleted. I have tried to play around with docker entrypoint commands but all of them seem to insist on a single line command with docker run
. Some help will be deeply appreciated! Thanks!
#!/bin/bash
FILE=$1
flag=1
while read line; do
#echo $line
#echo $flag
if [ $flag -gt 0 ] && [ $flag -lt 23189 ]; then
docker run --rm -v $(pwd):/eric -w /eric --entrypoint /bin/sh fedora -c "dnf info $line | tee -a manifest-fed:Core.txt; dnf repoquery --srpm $line"
((++flag))
elif [ $flag -gt 23188 ] && [ $flag -lt 46379 ]; then
docker run --rm -v $(pwd):/eric -w /eric --entrypoint /bin/sh fedora -c "dnf info $line | tee -a manifest-fed:Old.txt; dnf info $line"
((++flag))
elif [ $flag -gt 46378 ] && [ $flag -lt 69571 ]; then
docker run --rm -v $(pwd):/eric -w /eric --entrypoint /bin/sh fedora -c "dnf info $line | tee -a manifest-fed:Graphics.txt"
((++flag))
fi
done<"$1"
2
Answers
Create container in detached mode:
Run your commands in this container:
You may wrap those commands in a single script and put it in your
pwd
mapped to ‘/eric’ volume. And then execute them something like:Script
dnf-info.sh
may be: