Cloud Native 11 min read

Master Docker: Core Concepts, Installation, and Essential Commands

This guide introduces Docker’s fundamental concepts, explains its advantages and architecture, walks through installation steps, and provides a comprehensive list of common Docker commands for managing images and containers, including practical examples such as setting up SSH access within a container.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Docker: Core Concepts, Installation, and Essential Commands

1. Docker Basic Concepts

What is Docker?

Docker is an open‑source container platform that packages applications and all their dependencies into a standard unit called a container, which can run on any environment that supports Docker, ensuring portability and consistency.

Advantages of Docker

Consistency and portability : Containers run on any Docker‑enabled platform, keeping development and production environments identical.

Resource isolation and control : Containers share the host kernel, offering higher efficiency and fine‑grained resource allocation.

Fast deployment and startup : Containers start in seconds.

Simplified dependency management : All required libraries are bundled, eliminating “works on my machine” issues.

Docker Architecture

Image : A read‑only template containing the code, libraries, and configuration needed to run an application.

Container : A runnable instance of an image, providing an isolated execution environment.

Dockerfile : A text file with instructions to build an image.

Docker Hub : A cloud registry for sharing and retrieving images.

After installing Docker, the platform provides the ability to run containers, while specific applications are delivered as images, analogous to software running on an operating system.

Summary

Docker platform offers container runtime and management but does not contain applications.

Docker image packages a specific application with all its requirements.

Docker container is the running instance of an image.

2. Docker Installation

Refer to the linked article for detailed installation steps.

3. Common Docker Commands

In the following sections, CONTAINER denotes a container ID or name.

Image Management

Pull an image docker pull ubuntu:20.04 List images docker images Delete an image docker rmi ubuntu:20.04 Commit a container as a new image docker commit CONTAINER IMAGE_NAME:TAG Save an image to a local file docker save -o ubuntu-20.04.tar ubuntu:20.04 Load an image from a local file

docker load -i ubuntu-20.04.tar

Container Management

Create a container docker create -it ubuntu:20.04 List containers docker ps -a Start a container docker start CONTAINER Stop a container docker stop CONTAINER Restart a container docker restart CONTAINER Create and run a container

docker run -p 20000:22 --name mycontainer -itd ubuntu:20.04

Attach to a running container docker attach CONTAINER Execute a command inside a container docker exec CONTAINER COMMAND Remove a container docker rm CONTAINER Remove all stopped containers docker container prune Export a container to a file docker export -o xxx.tar CONTAINER Import a container from a file docker import xxx.tar image_name:tag View container processes docker top CONTAINER View container resource usage docker stats Copy files between host and container docker cp CONTAINER:src_path dest_path Rename a container docker rename CONTAINER NEW_NAME Update container resource limits

docker update CONTAINER --memory 500M --memory-swap 1G

These commands enable effective management of Docker images and containers for various development and deployment scenarios.

4. Docker Application Example

The following example demonstrates configuring SSH access inside a Docker container, effectively creating a lightweight virtual machine that can be accessed remotely.

Pull the Ubuntu image: docker pull ubuntu:20.04 Create and run a container with port 22 mapped to host port 20000:

docker run -p 20000:22 --name test1 -itd ubuntu:20.04

Attach to the container: docker attach test1 Set the root password inside the container: passwd Install and configure OpenSSH server:

apt update
apt install -y openssh-server
vim /etc/ssh/sshd_config   # set PermitRootLogin yes and PasswordAuthentication yes
service ssh start
service ssh status

From the host, connect via SSH: ssh root@localhost -p 20000 After completing these steps, you can log into the Docker container using SSH from the local machine.

To access the container from a remote computer, ensure the server’s port 20000 is open (see image below).

Then connect remotely: ssh root@<em>SERVER_PUBLIC_IP</em> -p 20000 Make sure the Docker container on the server is running; otherwise the SSH connection will fail.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerDevOpscontainerizationLinuxContainer ManagementSSHImage Management
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.