0

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
0

It looks like you are using redirection incorrectly (output of docker load redirected to alpine.tar):

docker load>alpine.tar

I 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 ID

This 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_container

I 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 exit

In your case, you should probably use $image_id instead of alpine:latest.

  • Thanks. docker load>alpine.tar works fine and the docker run command also run when I run it without -d option. But for this I have to type exit to come out of the container which I dont want. I want the container to automatically exit after it is started. – Ayesha Jul 11 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.