

-i (interactive) flag is to keep stdin open.For that we need to pass following flags in docker run command, What if we want to start our container and keep a live connection to its interactive shell. Which starts a bash session and ends it soon after that. If not overridden then by default centos or ubuntu docker containers run the /bin/bash command. Running a Docker container in interactive mode If you will provide any command for which there is no executable in container files ystem then it will throw error like this,Įrror response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"xyz\": executable file not found in $PATH": unknown. Now you can also stop this container with following command, Then will show that our container is still running i.e.ħd8e4ff176ba centos "ping localhost" About a minute ago Up About a minute nostalgic_jepsen During that time if we open an another terminal and check all running containers i.e. Now it keep running for next few seconds. To override the default command while running docker container pass the command in field of docker run command. Override default command while running a Docker container We can override this default command and make container to run another process on start. So, when we created and ran the container, it started and executed command /bin/bash and exited soon after that.

Like in case of centos image has default command is “/bin/bash”. Why did that happen ?īecause when we don’t provide any while running a container in docker run command then it runs the default command set in the image. It shows that container with ID “f497edf4ba16” started from centos image but its status is Exited i.e. We can confirm this by following commandĬONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESį497edf4ba16 centos "/bin/bash" 4 seconds ago Exited (0) 3 seconds ago admiring_hertz Well our container started and stopped instantly. If not then it will first fetch the centos image from repository and then start the container.īut, we got our prompt back, Is container running now ? It will first check if the docker engine has centos image or not. We can create and run a container using docker run command.
