Resource Management

Overview

This section outlines the core components of the Docker CLI’s resource management system. It covers how the CLI interacts with Docker resources like containers, images, networks, volumes, and secrets.

Docker Resource Management

The CLI manages Docker resources through a consistent set of commands and functionalities. Each resource type has a dedicated package (container, image, network, volume, secret) that handles its specific operations.

Common Resource Operations

Create:

  • Command: docker [resource_type] create
  • Example: docker container create -it ubuntu:latest
  • Description: Creates a new Docker resource of the specified type.

List:

  • Command: docker [resource_type] ls
  • Example: docker container ls -a
  • Description: Lists available Docker resources of the specified type.

Inspect:

  • Command: docker [resource_type] inspect [resource_id]
  • Example: docker container inspect <container_id>
  • Description: Displays detailed information about a specific resource.

Remove:

  • Command: docker [resource_type] rm [resource_id]
  • Example: docker container rm <container_id>
  • Description: Removes a Docker resource from the system.

Start:

  • Command: docker [resource_type] start [resource_id]
  • Example: docker container start <container_id>
  • Description: Starts a stopped resource.

Stop:

  • Command: docker [resource_type] stop [resource_id]
  • Example: docker container stop <container_id>
  • Description: Stops a running resource.

Restart:

  • Command: docker [resource_type] restart [resource_id]
  • Example: docker container restart <container_id>
  • Description: Restarts a resource.

Pause:

  • Command: docker [resource_type] pause [resource_id]
  • Example: docker container pause <container_id>
  • Description: Pauses a running resource.

Unpause:

  • Command: docker [resource_type] unpause [resource_id]
  • Example: docker container unpause <container_id>
  • Description: Unpauses a paused resource.

Resource Specific Operations

Containers:

  • Run: docker run [options] <image> [command]
  • Attach: docker attach [container_id]
  • Exec: docker exec [options] <container_id> [command]
  • Logs: docker logs [container_id]
  • Top: docker top [container_id]

Images:

  • Pull: docker pull <image_name>:<image_tag>
  • Push: docker push <image_name>:<image_tag>
  • Build: docker build [options] <context>
  • Tag: docker tag <image_name>:<image_tag> <new_image_name>:<new_image_tag>

Networks:

  • Connect: docker network connect <network_name> <container_name>
  • Disconnect: docker network disconnect <network_name> <container_name>
  • Create: docker network create <network_name>

Volumes:

  • Create: docker volume create <volume_name>
  • Mount: docker run -v <volume_name>:<mount_point> <image>

Secrets:

  • Create: docker secret create <secret_name> <file_path>
  • Use: docker run -e SECRET_NAME=<secret_name> <image>

Resource Management Packages

Container: github.com/docker/cli/cli/command/container/

Image: github.com/docker/cli/cli/command/image/

Network: github.com/docker/cli/cli/command/network/

Volume: github.com/docker/cli/cli/command/volume/

Secret: github.com/docker/cli/cli/command/secret/