

The reason for running bash as command here is that the container won’t stop immediately.


The -d option (daemon mode) keeps the container running in the background.The -t option gives you a terminal (so that you can use it as if you used ssh to enter the container).The -i option means that it will be interactive mode (you can enter commands to it).The above command will create a new container with the specified name from the specified docker image. If you want to run a docker container with a certain image and a specified command, you can do it in this fashion: docker run -it -d -name container_name image_name bash I’ll explain in detail what the above two commands do and what is the -it option in the docker run and exec command. :~$ docker exec -it my_container bashīin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var Here’s an example where I create a new container with Ubuntu as the base image and then I enter the running Ubuntu container and run the ls command: :~$ docker run -it -d -name my_container ubuntu bashħe77640bca686108ad415318278a1fa148e1c84d3b180276e19ec2b970ba9b67 You can create and run a container with the following command: docker run -it -d -name container_name image_name bashĪnd then, if you want to enter the container (to run commands inside the container interactively), you can use the docker exec command: docker exec -it container_ID_or_name /bin/bash
Docker run image from command line how to#
So, if you are new to Docker, you might wonder how to run a docker container.
