Back

Explore Courses Blog Tutorials Interview Questions

Explore Tech Questions and Answers

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

0 votes
2 views
by (2.3k points)

So i've been learning docker recently and according to this docker tutorial I was reading, using the "docker run -d" command will start up a new docker container from the referenced image, and this container will run in the background.

This is exactly how I typed it out :

root@docker:/home/root# docker run -d centos
605e3928cdddb844526bab691af51d0c9262e0a1fc3d41de3f59be1a58e1bd1d

But I think my container is not working properly as when I type in the command: docker ps I get nothing.

But when I type in the command: docker ps -a, it shows me the container, but its status is listed as "Exited" :

root@docker:/home/root# docker ps -a
CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS                         PORTS               NAMES
605e3928cddd        centos:latest         "/bin/bash"         31 minutes ago      Exited (0) 31 minutes ago                          kickass_swartz

Can anyone help me out? why is it showing the container like this?

1 Answer

0 votes
by (6.9k points)

The container shell exits immediately as you are using Centos and the centos dockerfile uses bash as its default command, this will happen when you are running a container in the background ( using the -d flag ).

In the latest version of docker you are authorized to run a docker container both in foreground mode as well as the detached mode ( -it flag )

In any case, this should be enough :

docker run -t -d centos

Hope that helped :)


If you are looking to master docker make sure you try docker training course. 

Browse Categories

...