Reputation: 73
I am running docker run container command in 2 ways
docker container run 4e5021d210f6
docker container run -d 4e5021d210f6
what is the difference between the execution of command 1 and command 2?
Upvotes: 2
Views: 6342
Reputation: 293
You must use
docker ps
to see containers running id, status etc, you can also use
docker run -it image_name bash
if you want to run commands through your terminal inside the container.
-d
option is mostly used when you have defined some operations with a Dockerfile and you don't want to interact with the container. So, you run your image's container in --detach (-d) mode, to run in the background.
Notice, that you have to perform docker stop container_id
in order to stop it.
Upvotes: 2
Reputation: 7432
The -d
parameter indicates to Docker that you do not want to attach to the container through stdin/out. In other words, you are asking to run the container in a background, non-interactive mode. The string printed is the unique ID of the newly created container which you can use with commands like docker inspect
In either command you're executing, your containers are only running for a very short amount of time before stopping. This can be because the container requires arguments to docker run
, or because the container performs a one-time task or job before exiting. Therefore, the end-result you observe is the same. If the -d
were omitted and the container ran for a longer amount of time you would see this more clearly
Upvotes: 1
Reputation: 3450
-d
will run the container in the background. It's the same as adding --detach
. What is being printed when you use -d
is the container's ID.
https://docs.docker.com/engine/reference/commandline/run/
Upvotes: 4