Must-know Docker commands for power users.

 

Container Management

  • docker ps # Lists running containers
  • docker ps -a # Lists all containers (including stopped ones)
  • docker run [image] # Creates and runs a container based on an image
  • docker start [id/name] # Starts a stopped container
  • docker stop [id/name] # Stops a running container
  • docker restart [id/name] # Restarts a container
  • docker rm [id/name] # Removes a stopped container
  • docker exec -it [id/name] /bin/sh # Runs a command inside a container
  • docker logs [id/name] # Shows the logs of a container
  • docker inspect [id/name] # Shows details of a container
  • docker port [id/name] # Shows the ports assigned to a container
  • docker stats [id/name] # Displays resource usage statistics for containers
  • docker top [id/name] # Shows running processes inside a container

Image Management

  • docker images # Lists available images locally
  • docker pull [image] # Downloads an image from a repository
  • docker rmi [image] # Removes a local image
  • docker build -t [image-name] . # Builds an image from a Dockerfile
  • docker tag [id/name] [new-name] # Tags an image
  • docker push [image-name] # Pushes an image to a repository

Volume Management

  • docker volume create [volume-name] # Creates a volume
  • docker volume ls # Lists all volumes
  • docker volume inspect [volume-name] # Shows details of a volume
  • docker volume rm [volume-name] # Removes a volume

Docker Networks

  • docker network ls # Lists all networks
  • docker network create [network-name] # Creates a network
  • docker network inspect [network-name] # Shows details of a network
  • docker network connect [network-name] [container-id/name] # Connects a container to a network
  • docker network disconnect [network-name] [container-id/name] # Disconnects a container from a network
  • docker network rm [network-name] # Removes a network

Docker Compose Management

  • docker-compose up # Starts the services defined in docker-compose.yml
  • docker-compose down # Stops and removes the containers, networks, and volumes created by docker-compose
  • docker-compose ps # Lists containers managed by docker-compose
  • docker-compose logs # Shows logs of services managed by docker-compose
  • docker-compose exec [service] [command] # Runs a command inside a container managed by docker-compose
  • docker-compose build # Builds images defined in docker-compose.yml
  • docker-compose pull # Pulls images defined in docker-compose.yml
  • docker-compose restart # Restarts services managed by docker-compose

Inspection and Debugging

  • docker inspect [resource] # Shows details of any resource (container, image, network, volume)
  • docker events # Shows real-time events from the Docker engine
  • docker info # Displays detailed information about the Docker environment
  • docker history [image] # Shows the build history of an image
  • docker diff [id/name] # Shows filesystem changes in a container
  • docker logs -f [id/name] # Follows the logs of a container in real-time

Other Useful Commands

  • docker system df # Shows disk usage by images, containers, and volumes
  • docker system prune # Removes unused data (stopped containers, unreferenced images, etc.)
  • docker attach [id/name] # Attaches to the console of a running container
  • docker cp [id/name]:[path-inside] [local-path] # Copies files from a container to your local machine
  • docker save -o [file.tar] [image] # Saves an image to a tar file
  • docker load -i [file.tar] # Loads an image from a tar file
  • docker export [id/name] > [file.tar] # Exports the filesystem of a container
  • docker import [file.tar] # Imports a tar file as a Docker image

 

Comments

Popular posts from this blog

Unveiling the "TOP" command: Analyze your system like a power user.

How to Install Stable Diffusion on Windows