Docker Basics, Commands, and Key Concepts
Jan 11. 2022

AI Summary
This AI-generated content is derived from the source article.

Docker consists of images, containers, and repositories. Images serve as templates for creating immutable containers, which are lightweight and ideal for microservices. Docker operates on a client-server model, utilizing a daemon for management. Key commands include creating, starting, and managing containers and images, as well as handling networks.

Docker

Image

  • A template that can be used to create container services.
  • Images are immutable and consist of multiple layers.
  • Commonly used base images include ubuntu, alpine, and node.

Container

  • Independently runs one or a group of applications, created from an image.
  • A simplified Linux system.
  • Containers are lightweight and portable, making them ideal for microservices.

Repository

  • A place to store images.
  • Divided into public and private repositories.
  • Popular public repositories include Docker Hub and GitHub Container Registry.

Underlying Principles

How It Works

  • A Client-Server structured system, where Docker’s daemon runs on the host.
  • DockerServer receives commands from Docker-Client.
  • Docker uses namespaces for isolation and cgroups for resource management.

Key Components

  • Docker Daemon: Runs on the host machine and manages Docker objects.
  • Docker CLI: A command-line interface to interact with the Docker Daemon.
  • Docker Compose: A tool for defining and running multi-container applications.

Commands

Container

docker container my_commandcreate — Create a container from an image. start — Start an existing container. run — Create and start a new container. ls — List running containers. inspect — View detailed information about a container. logs — Print logs. stop — Gracefully stop a running container. kill — Abruptly stop the main process in a container. rm — Remove a stopped container. exec — Run a command inside a running container. cp — Copy files or directories between a container and the host.

Image

  • Use docker image my_commandbuild — Build an image. push — Push an image to a remote registry. pull — Download an image from a remote registry. ls — List images. history — View intermediate image information. inspect — View detailed information about an image, including layers. rm — Remove an image. tag — Tag an image for easier reference.

Network

  • Use docker network my_commandcreate — Create a new network. ls — List all networks. inspect — View detailed information about a network. rm — Remove a network. connect — Connect a container to a network. disconnect — Disconnect a container from a network.

Docker Syntax

> comment on / twitter
> cd ..
CC BY-NC-SA 4.0 2021-PRESENT © RYANUO