Trying to run a docker container through a bash script. I need the container to start and exit as soon as it is started in the bash script so that I will note the time it took for starting the container. Image is a tar file, copied from another machine using save and load technique. Can run a container from the image in the terminal but not in the shell script using docker run -it imageId command.It displays error "docker:Error response from daemon:OCI runtime create failed:container_linux.go starting process caused executable file not found in $PATH: unknown. Help is highly appreciated. Thanks
tl_start=$(date +%s)
docker load>alpine.tar
tl_end$(date +%s)
tl_load=$((tl_end-$tl_start))
image_id=$(docker images -a | awk '$2 ~/none/print{print $3}')
ts_start=$(date +%s)
docker run -i -d alpine:latest $image_id 1 Answer
It looks like you are using redirection incorrectly (output of docker load redirected to alpine.tar):
docker load>alpine.tarI would suggest that you download alpine.tar from the other machine again (since it could be corrupt now) and then use docker load -i alpine.tar instead.
Since the image isn't loaded correctly, it would explain why the create command fails and $image_id is invalid. I would suggest to add a check that image_id is correctly set.
Measuring the start time of the container solely on when docker run returns to the shell would not be true measure of start time. From the docker run documentation:
--detach , -d Run container in background and print container IDThis means that it will run in the background and just because it returns to the shell does not mean that the container is actually fully up and running.
You are also using $image_id as the name of the container you're starting, and I'm guessing you want to start a container with the actual image you just loaded. It would make more sense with something like:
docker run -i -d $image_id test_containerI would instead suggest to have a HEALTHCHECK or ENTRYPOINT instruction in the Dockerfile that would print something when it is actually fully up and running.
It is possible to stop/exit the container directly by specifying the entrypoint script being a shell, and then send a command to that shell, in this case exit:
docker run -it -d --entrypoint=/bin/sh alpine:latest exitIn your case, you should probably use $image_id instead of alpine:latest.