| by Gagandeep Singh | No comments

Docker – useful commands

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


Show running containers

docker ps

docker ps –all

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


Restart stopped containers

docker start <container id>

example:

run docker ps –all to get the list of containers

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

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 pixxstudios.com)


Remove stopped containers

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.