extremely-useful-docker-commands

xtremely useful docker commands

No matter if you’re just getting started with docker or you’re already a professional, there are situations when you can’t remember the correct command or you’re just confused by the order of parameters.

Therefore we decided to create our own docker commands cheat sheet and share it with you.

Whenever you build your own container or you want to timestamp the container you’re using and worked with your applications – check the free timestamping service: Timestamp service for code and container

Top 16 docker commands

  1. docker ps  list running containers. 
  2. docker ps -a list all container including stopped container
  3. docker pull  download a image from Docker Hub registry. Link to the docker image is always shown on the right at dockerhub.
  4. docker build  is used to build your own container based on a Dockerfile. Common use is docker build . to build a container based on the Dockerfile in the current directory (the dot). docker build -t "myimage:latest" . creates a container and stores the image under the given name
  5. docker images or docker image ls shows all local storage images
  6. docker run  Run a docker container based on an image, i. e. docker run myimage -it bash. If no local image can be found docker run automatically tries to download the image from Docker hub.
  7. docker logs display the logs of a container, you specified. To continue showing log updates just use docker logs -f mycontainer
  8. docker volume ls  lists the volumes, which are commonly used for persisting data of Docker containers.
  9. docker network ls – list all networks available for docker container
  10. docker network connect adds the container to the given container network. That enables container communication by simple container name instead of IP.
  11. docker rm   removes one or more containers. docker rm mycontainer, but make sure the container is not running
  12. docker rmi  removes one or more images. docker rmi myimage, but make sure no running container is based on that image
  13. docker stop   stops one or more containers. docker stop mycontainer stops one container, while docker stop $(docker ps -a -q) stops all running containers. 
  14. docker start – starts a stopped container using the last state
  15. docker update –restart=no updates container policies, that is especially helpful when your container is stuck in a crash loop
  16. docker cp to copy files from a running container to the host or the way around. docker cp :/etc/file . to copy /etc/file to your current directory.

Some combinations that help a lot:

  • kill all running containers with docker kill $(docker ps -q)
  • delete all stopped containers with docker rm $(docker ps -a -q)
  • delete all images with docker rmi $(docker images -q)
  • update and stop a container that is in a crash-loop with docker update –restart=no && docker stop
  • bash shell into container docker exec -i -t /bin/bash – if bash is not available use /bin/sh
  • bash shell with root if container is running in a different user context docker exec -i -t -u root /bin/bash

What about resource usage 

Get docker container including size: docker ps -s

docker commands

Get docker container disk utilization: docker system df

docker system df

What about wasted resources?

The first command is used to remove local container images that are not used by any container and are not tagged. Its a pretty safe command to clean up your local filesystem

docker image prune

If you want to clean up and delete all unused container images, just add -a

docker image prune -a

only clean up container images that have been created over 24 hours ago run

docker image prune -a –filter "until=24h"

same can be done with container, that are not running anymore

docker container prune

Here comes a bonus command:

truncate -s 0 $(docker inspect --format='{{.LogPath}}' <container_name_or_id>)

That’s it for now – please let us know if you like to add a command you feel is extremely important. We’re doing our best to add these in future blog posts are just append to the current posts. 

Btw. as we covered the Podman project some days ago, most of these commands work with podman instead of docker as well.

CNIL
Metrics and Logs

(formerly, Opvizor Performance Analyzer)

VMware vSphere & Cloud
PERFORMANCE MONITORING, LOG ANALYSIS, LICENSE COMPLIANCE!

Monitor and Analyze Performance and Log files:
Performance monitoring for your systems and applications with log analysis (tamperproof using immudb) and license compliance (RedHat, Oracle, SAP and more) in one virtual appliance!

Subscribe to Our Newsletter

Get the latest product updates, company news, and special offers delivered right to your inbox.

Subscribe to our newsletter

Use Case - Tamper-resistant Clinical Trials

Goal:

Blockchain PoCs were unsuccessful due to complexity and lack of developers.

Still the goal of data immutability as well as client verification is a crucial. Furthermore, the system needs to be easy to use and operate (allowing backup, maintenance windows aso.).

Implementation:

immudb is running in different datacenters across the globe. All clinical trial information is stored in immudb either as transactions or the pdf documents as a whole.

Having that single source of truth with versioned, timestamped, and cryptographically verifiable records, enables a whole new way of transparency and trust.

Use Case - Finance

Goal:

Store the source data, the decision and the rule base for financial support from governments timestamped, verifiable.

A very important functionality is the ability to compare the historic decision (based on the past rulebase) with the rulebase at a different date. Fully cryptographic verifiable Time Travel queries are required to be able to achieve that comparison.

Implementation:

While the source data, rulebase and the documented decision are stored in verifiable Blobs in immudb, the transaction is stored using the relational layer of immudb.

That allows the use of immudb’s time travel capabilities to retrieve verified historic data and recalculate with the most recent rulebase.

Use Case - eCommerce and NFT marketplace

Goal:

No matter if it’s an eCommerce platform or NFT marketplace, the goals are similar:

  • High amount of transactions (potentially millions a second)
  • Ability to read and write multiple records within one transaction
  • prevent overwrite or updates on transactions
  • comply with regulations (PCI, GDPR, …)


Implementation:

immudb is typically scaled out using Hyperscaler (i. e. AWS, Google Cloud, Microsoft Azure) distributed across the Globe. Auditors are also distributed to track the verification proof over time. Additionally, the shop or marketplace applications store immudb cryptographic state information. That high level of integrity and tamper-evidence while maintaining a very high transaction speed is key for companies to chose immudb.

Use Case - IoT Sensor Data

Goal:

IoT sensor data received by devices collecting environment data needs to be stored locally in a cryptographically verifiable manner until the data is transferred to a central datacenter. The data integrity needs to be verifiable at any given point in time and while in transit.

Implementation:

immudb runs embedded on the IoT device itself and is consistently audited by external probes. The data transfer to audit is minimal and works even with minimum bandwidth and unreliable connections.

Whenever the IoT devices are connected to a high bandwidth, the data transfer happens to a data center (large immudb deployment) and the source and destination date integrity is fully verified.

Use Case - DevOps Evidence

Goal:

CI/CD and application build logs need to be stored auditable and tamper-evident.
A very high Performance is required as the system should not slow down any build process.
Scalability is key as billions of artifacts are expected within the next years.
Next to a possibility of integrity validation, data needs to be retrievable by pipeline job id or digital asset checksum.

Implementation:

As part of the CI/CD audit functionality, data is stored within immudb using the Key/Value functionality. Key is either the CI/CD job id (i. e. Jenkins or GitLab) or the checksum of the resulting build or container image.

White Paper — Registration

We will also send you the research paper
via email.

CodeNotary — Webinar

White Paper — Registration

Please let us know where we can send the whitepaper on CodeNotary Trusted Software Supply Chain. 

Become a partner

Start Your Trial

Please enter contact information to receive an email with the virtual appliance download instructions.

Start Free Trial

Please enter contact information to receive an email with the free trial details.