Docker - useful commands

Page content

To run a container using an image

docker run <image name>

example: docker run hello-world

Override the default command for a container

docker run <image name> command

example: docker run busybox ls

docker run busybox ls

Show running containers

docker ps

docker ps

docker ps --all

This will list all the containers that were ever created on your machine.

docker ps -all

Restart stopped containers

docker start <container id>


run docker ps –all to get the list of containers

run docker ps –all

copy the container id of the stopped container (It will have a status as exited) that you want to restart.

run docker ps –all

It will start the container and use the optional -a flag to log the default output of that container (In the above case it’s ping

Remove stopped containers

docker system prune

docker system prune

Get logs from a container

docker logs <container id>

Stopping a container

docker stop <container id>

Give container 10 seconds to wrap up whatever its doing and then stop the container.

docker kill <container id>

Just stop whatever process is running in the container immediately and then stop the container itself.