A "work in progress"-list with the Docker commands I use the most

The last months I begun using Docker Containers in the projects I am working on. Working with a command line tool (Windows Powershell, etc.) is essential when creating new containers. In this article I would like to share with you my favorite commands that I use the most as a reference:

  • docker ps:
    • Lists all running containers in the current machine
    • Alternative you can use the docker container ls command which also lists all running containers


  • docker ps -a:
    • Lists all containers (running or not)
    • Alternative you can use the docker container ls -a command which also lists all containers


  • docker image ls:
    • Lists all, not deleted, images we have created


  • docker build -t aRandomName:aRandomVersion .:
    • builds a new image with the given name and version (optional option)
    • The command has to be executed inside a folder which container a Dockerfile file
    • The . is the path where the local files are being sent to when we create the new image
    • use the –no-cache option if you want to build the image from scratch


  • docker run -d IMAGE_ID:
    • Starts a new container instance with the specified image id. The id can be found with docker image ls
    • the -d option instructs the container to run in the background
    • alternative to -d, you can use the -it option which tells Docker to create a bash shell in the container, so that we can directly interact with it


  • docker start CONTAINER_ID:
    • Starts a new container instance with the specified container id. The id can be found with docker ps -a


  • docker stop CONTAINER_ID:
    • Stops a container with the given id


  • docker image rm -f IMAGE_ID:
    • Removes a created image with the given id. The id can be found with the docker image ls command
    • -f is for force


  • docker exec -it CONTAINER_ID bash:
    • Starts the container with the given id
    • The -it option instructs Docker to directly open the bash shell


  • docker container inspect CONTAINER_ID:
    • Returns a JSON object with the complete configuration of the container


  • docker attach CONTAINER_ID
    • Attach to a running container

For a more detailed documentation of the previous commands and their available option visit the Docker documentation.

comments powered by Disqus