Docker commands cheatsheet

docker commands


I’ve been playing around with my ASP.NET Core microservices on Linux. In the meantime I have build my front-end build pipeline and tried to understand Xamarin Visual Studio Templates. I wanted to start using docker with coreclr in order to have full cross platform development environment. I have failed this on Windows, so now playing around with Ubuntu. This post will be about some must known commands in Docker, that can help you with diagnosing issues.

Docker commands

List all images

  • List all installed images
$ docker images
REPOSITORY          TAG                         IMAGE ID            
userservice         latest                      b0b53852abc1        
myapp               latest                      a5de8472bfe4        
microsoft/aspnet    1.0.0-rc1-update1-coreclr   293bc8bb585b        
microsoft/aspnet    latest                      78819b81e69a        
hello-world         latest                      94df4f0ce8a4

Build image

$ docker build -t userservice .

Force remove image by ID

  • Force remove existing image
  • Sample
$docker rmi -f 32b061e1713e
Deleted: sha256:32b061e1713ebf4c4fe229fe0afc87a9b5a3384ce29855b9821421f5a2e0631c
Deleted: sha256:032adb2204a03c86eefb38d293bb1c3113d7cc432c7d10a0a5d195354ee14604

Docker list running container

  • List all running containers
mogluszka@mogluszkaW540:~/Sources/shout/src/userService$ docker ps
399a982bd881 userservice "dnx kestrel" Up 47 minutes 5000/tcp cocky_easley

Docker kill

  • Kills any running container
$ docker kill 399a982bd881

Docker kill’em all

$ docker stop $(docker ps -a -q)

Docker remove all images

  • Removes all images
$ docker rmi $(docker images -q)

Docker logs

  • Shows logs from container
mogluszka@mogluszkaW540:~/Sources/shout/src/userService$ docker logs c4035a691a64
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

Docker Inspect

  • Shows details of your container

Docker Inspect IP

  • Shows specific IP of your docker container
  • Sample
  • mogluszka@mogluszkaW540:~/Sources/shout/src/userService$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' c4035a691a64

    Docker run bash

    • You can run bash in your container
    • Sample
    $ docker exec -t -i c4035a691a64 /bin/bash


    This are some docker commands that I use on daily basis. If you believe you find it useful, please follow me on Twitter, sign up to newsletter, like on Facebook or just visit me from time to time. I’ll try to keep this up to date.

    One thought on “Docker commands cheatsheet

    Leave a Reply

    Your email address will not be published. Required fields are marked *