'docker exec' can only used on running container, but what is the meaning of running container? Is that means the container should be computing something? or is the issue about the [command] which I define for the container? Why my TensorFlow container always be stopped status?
After I used 'docker run' to build a tensorflow container, the container stopped automatically. I need to restart it and then execute command on it. Why the container cannot be always in running since I build it?
docker run -it --runtime=nvidia tensorflow/tensorflow:latest-gpu-py3
It will then pops up a bash which I can use to control the container. But after I exit, the container stopped itself. Which means, I can only use docker ps -a
to see my container but docker ps
can not. I have to restart the container if I want to use my container again.
UPDATE1: If I want create a container like VM, I cannot use docker run
with a temporal [command]
like python ..
. The container will lose control permanently after the command finished. docker restart
cannot start the container again. Hence, docker exec
cannot apply on it. Instead, using bash
or nothing as the [command]
can create a container which can be restart, therefore, can be applied withdocker exec
.
UPDATE2: docker run -d -it
can create a running container (but the bash shell won't pops up, neither even with bash
). Directly using docker exec -it container_name bash
can take the control of the running container again, without docker restart
. In this time, exiting bash shell will not stop the container.