

If you do not use the -d option, docker run will create a new container and you’ll have a terminal in interactive mode running bash shell.Īs you can see in the example below, the container is created and I am automatically inside the container (bash shell). What happens if you don’t run it as a daemon (-d option) in the background?

In the above example, I didn’t name the container so it was randomly named determined_blackburn.Īnd as you can see, the container is running bash command in the background. :~$ docker run -it -d ubuntu bashĨ2766613e7bc0ae98887bb1c776fa0de7f3c4771db9ac7ffc5db5c2c68ab497bĬONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESĨ2766613e7bc ubuntu "bash" 4 seconds ago Up 3 seconds determined_blackburn 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 INTERACTIVE HOW TO
So, if you are new to Docker, you might wonder how to run a docker container.
