Yasir Iqbal ITS
Yasir Iqbal ITS

Reputation: 55

Docker command difference

I am new to docker container. Can someone please tell me what is difference between these two commands. In my knowledge, have the same out put than why we use the bash command.

docker run -it ubuntu 
docker run -it ubuntu bash

Upvotes: 1

Views: 87

Answers (2)

Rafaf Tahsin
Rafaf Tahsin

Reputation: 8626

In docker, we run a linux container. As you know, a linux system is alive when it's init 0 service is alive. 'init 0' is kind of the heart of a linux system. when 'init 0' is killed, the linux system also dies.

In a containerized architecture, you run a container for simply one purpose i.e. to simply run one service. If the service fails, we want the container to also die. So we define the service as init 0 job for the container.

When you run docker run -it ubuntu bash, here, bash is the init 0 job for the container. As soon as you exit from bash, the container stops working.

Instead of using bash you can also try other commands like @Shmuel suggested.

Well, when we create custom images, we often want to pre-define default 'init 0' job for our custom image. If the 'init 0' is predefined, you don't need to mention it in docker run command.

In ubuntu image, the pre-defined 'init 0' job is bash. So, if you don't mention bash in the run command, it works in a similar manner.

Upvotes: 1

Shmuel
Shmuel

Reputation: 1678

docker run -it ubuntu let's you run command inside the container.

The bash is the command to run.

For example instead you can run

docker run -it ubuntu ls /home

This will list the /home dir inside the container.

Upvotes: 0

Related Questions