☠️
smadi0x86 Playground
  • 💀Welcome to smadi0x86 Playground
    • 🍷Resources
    • 🚬Projects
    • 🎓Certifications
    • 📌Pinned
    • ❓Questions
    • 📞Contact
  • 🏞️Cloud Native
    • Docker
      • Quick Reference
      • Introduction
      • Containers
      • Images
      • Storage & Volumes
      • Security
      • Cheatsheet
    • Git
    • Serverless Framework
    • YAML
  • 🔨Software Engineering
    • System Design
    • Environment Variables
    • JSON Web Tokens
  • 👾Architecture
    • C Language
      • Introduction
      • Calling Conventions
      • GCC Compilation
      • Libraries & Linking
      • I/O
      • Files
      • Pointers
      • Dynamic Memory Allocation
      • Data Types
      • Strings Manipulation
      • Bit Manipulation
      • Pre-processors
      • Macros
      • Type Qualifiers
    • C/C++ Build Systems
      • Fundamentals for Linking
      • Symbolic Linking
      • Cross-Platform Compilation
      • CMake for Building and Linking
      • Shared Libraries
      • Dynamic Linking and Dependency Management
    • Operating Systems
      • OS & Architecture
      • Processes
      • CPU Scheduling
      • Memory Management
  • 🛩️Cyber Warfare
    • Flight Physics
    • Communication
      • PWM & PPM
      • MAVLink
  • 🏴‍☠️Offensive Security
    • Active Directory
      • Introduction
    • Web Attacks
      • Server Side
        • OS Command Injection
        • Information Disclosure
        • Directory Traversal
        • Business Logic
        • Authentication
        • File Upload
        • SSRF
      • Client Side
        • CSRF
        • XSS
    • Recon
      • Active
        • Host discovery
        • Nmap
        • Mass Scan
      • Passive
        • Metadata
      • Web Applications
        • Discovery
        • Subdomains & Directories
        • SSL Certs
        • CMS
        • WAF Detection
      • Firewall Evasion
  • Binary Exploitation
    • Stack Smashing
      • x86
      • x86_64
    • pwntools
      • Processes and Communication
      • Logging and Context
      • Cyclic
      • Packing
      • ELF
      • ROP
  • 😈Advanced Persistent Threat
    • C2
      • Sliver
    • Malware
      • Windows Internals
        • PEB
      • Academy
        • Basics
      • Sektor7
        • Essentials
  • 💌Certifications
    • AWS Certified Cloud Practitioner (CLF-C01)
      • Cloud Foundations
      • Domain 1: Cloud Concepts
      • Domain 2: Security and Compliance
      • Domain 3: Technology
      • Domain 4: Billing and Pricing
    • AWS Certified Solutions Architect - Associate (SAA-C03)
      • Foundation
    • Certified Kubernetes Administrator (CKA)
      • Core Concepts
      • Scheduling
      • Logging & Monitoring
      • Application Lifecycle Management
      • Cluster Maintenance
      • Security
      • Storage
      • Networking
      • Design Kubernetes Cluster
      • Kubernetes The Kubeadm Way
      • Troubleshooting
      • JSONPATH
      • Lightning Lab
      • Mock Exams
      • Killer Shell
    • Certified Kubernetes Security (CKS)
      • Foundation
      • Cluster Setup
      • Cluster Hardening
      • Supply Chain Security
      • Runtime Security
      • System Hardening
      • Killer Shell
    • (KGAC-101) Kong Gateway Foundations
      • Introduction to APIs and API Management
      • Introduction to Kong Gateway
      • Getting Started with Kong Enterprise
      • Getting Started with Kong Konnect
      • Introduction to Kong Plugins
  • 📜Blog Posts
    • Modern Solutions For Preventing Ransomware Attacks
Powered by GitBook
On this page
  • Setting Up Docker
  • Install Docker
  • Docker Images
  • Building an Image
  • Listing Images
  • Removing an Image
  • Removing All Images
  • Docker Containers
  • Running a Container
  • Listing Running Containers
  • Listing All Containers
  • Stopping a Container
  • Removing a Container
  • Removing All Containers
  • Debugging and Interactivity
  • Running a Container Interactively
  • Bash Into a Running Container
  • Maintenance and Cleanup
  • Removing Stopped Containers, Unused Volumes, and Networks
  • Removing Unused Images
  • Other Handy Commands
  • Viewing Logs of a Container
  • Copying Files from/to a Container
  • Debugging and Interactivity with Docker Containers
  • Entering a Container's Shell
  • Running a Container with an Interactive Shell
  • Viewing Container Logs
  • Inspecting Container Metadata
  • Checking Container Processes
  • Debugging a Container That Won't Start
  1. Cloud Native
  2. Docker

Quick Reference

Docker common commands reference

PreviousDockerNextIntroduction

Last updated 1 year ago

Setting Up Docker

Install Docker

Refer to the official Docker documentation for OS-specific installation instructions.

Verify Docker installation:

docker --version

Docker Images

Building an Image

To create a Docker image from a Dockerfile:

docker build -t your-image-name:tag .
  • your-image-name: Name of the image.

  • tag: Version tag (commonly latest for the most recent version).

Listing Images

To view all Docker images on your system:

docker images

Removing an Image

To remove a specific Docker image:

docker rmi your-image-name:tag

Removing All Images

To remove all Docker images:

docker rmi $(docker images -q)

Docker Containers

Running a Container

To run a Docker container from an image:

docker run -p host-port:container-port your-image-name:tag

Listing Running Containers

To view all running containers:

docker ps

Listing All Containers

To see all containers, including stopped ones:

docker ps -a

Stopping a Container

To stop a specific running container:

docker stop container-id-or-name

Removing a Container

To remove a stopped container:

docker rm container-id-or-name

Removing All Containers

To remove all containers:

docker rm $(docker ps -aq)

Debugging and Interactivity

Running a Container Interactively

To run a container in interactive mode (often used with a shell):

docker run -it your-image-name:tag /bin/sh

Bash Into a Running Container

To enter the shell of a running container:

docker exec -it container-id-or-name /bin/sh

Maintenance and Cleanup

Removing Stopped Containers, Unused Volumes, and Networks

To perform a cleanup:

docker system prune

Removing Unused Images

To remove dangling (unused) images:

docker system prune -a

Other Handy Commands

Viewing Logs of a Container

To view the logs of a running or stopped container:

docker logs container-id-or-name

Copying Files from/to a Container

To copy files between your host and a container:

# From container to host
docker cp container-id-or-name:/path/in/container /path/on/host

# From host to container
docker cp /path/on/host container-id-or-name:/path/in/container

Debugging and Interactivity with Docker Containers

Debugging containers often requires entering the container's environment, executing commands, or inspecting files. Here's how to navigate these tasks.

Entering a Container's Shell

Sometimes, to debug or inspect the container's internals, you may want to get a shell inside a running container. Here's how you can do that:

docker exec -it container-id-or-name /bin/sh
  • If the container is using a different shell, you might need to replace /bin/sh with /bin/bash or another appropriate shell.

Running a Container with an Interactive Shell

If you are just starting a container and want it to give you a shell immediately, use:

docker run -it your-image-name:tag /bin/sh

Again, replace /bin/sh if a different shell is used in the container.

Viewing Container Logs

To view the logs produced by a running or a stopped container:

docker logs container-id-or-name

Inspecting Container Metadata

For a detailed report on a container (like IP addresses, volumes, environment variables, etc.):

docker inspect container-id-or-name

Checking Container Processes

To see which processes are running inside a container:

docker top container-id-or-name

Debugging a Container That Won't Start

If a container is failing to start, it's often useful to override its entrypoint to keep it running and then bash into it to inspect:

docker run -it --entrypoint /bin/sh your-image-name:tag

This will override the container's default entry point with a shell, allowing you to start the intended command manually or inspect why it might be failing.

Install docker on windows
Install docker on linux
🏞️
Page cover image