Docker - useful commands

ยท 174 words ยท 1 minute read

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 &ndash;all

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

run docker ps &ndash;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.