We can also pass the name flag in docker run command to assign a name to the container i.e.ĭocker run -name varun_centos -it centos
#Docker run image to container how to
To exit from this terminal and go back to our host box type exit i.e.Ĭ:\Varun\box> How to create and run a docker container with custom name You can also run other commands and test stuff, all commands executed through this shell will run inside container only. Now this command was executed inside container and output was shown in our terminal. Let’s execute ls command i.e.Īnaconda-post.log bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var Now we can execute commands in this shell. Once centos container started, it executed /bin/bash by default and -it flag forced it to keep stdin open and assign a interactive terminal for us. Let’s run a centos container and keep it’s shell open in interactive mode i.e.
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.