惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
量子位
月光博客
月光博客
人人都是产品经理
人人都是产品经理
U
Unit 42
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
H
Help Net Security
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
MyScale Blog
MyScale Blog
美团技术团队
P
Proofpoint News Feed
Apple Machine Learning Research
Apple Machine Learning Research
D
Docker
B
Blog
大猫的无限游戏
大猫的无限游戏
V
Visual Studio Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Docker – Port Mapping, Logs, Container Management, and Im...
Ramya Perumal · 2026-06-28 · via DEV Community
Cover image for Docker – Port Mapping, Logs, Container Management, and Image Removal

Ramya Perumal

Docker – Logs, Remove, and Port Mapping

Port Mapping

When we run an application inside a container, we define the port on which the application will run. The container runs the application on that port.

It is not possible to access an application running inside Docker from outside the container unless port mapping is configured.

Port mapping is specified using the -p option.

Syntax:

docker run -p <host_port>:<container_port>

Example:

docker run -p 8888:8080

Here:

  • 8888 is the host (machine) port used to access the application from outside the container.
  • 8080 is the port defined in the application and exposed inside the container.

If the host port is already in use, Docker displays an error message.

How to Check Which Ports Are Being Used by Docker Containers

docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"


Detached Mode

To run a container in detached mode, use the -d option.

docker run -d -p 2000:2001

Detached mode means the container runs in the background.


Docker Logs

Logs contain information about the activities happening inside a container.

View Logs of a Specific Container

docker logs <container_id>

Follow Logs Continuously

docker logs -f <container_id>

-f stands for follow.

View Logs from a Specific Time Range

Seconds (s): docker logs --since 30s <container_id>
Minutes (m): docker logs --since 5m <container_id>
Hours (h): docker logs --since 2h <container_id>

Docker supports seconds (s), minutes (m), and hours (h) for relative time.

For days, weeks, months, or years, use an ISO 8601 date or timestamp.

Weeks:  docker logs --since 2026-06-14 <container_id>
Months: docker logs --since 2026-05-21 <container_id>
Years:  docker logs --since 2025-06-21 <container_id>

Combined Time Units

docker logs --since 1h30m <container_id>

Displays logs from 1 hour and 30 minutes ago.

Exact Time

docker logs --since "2026-06-21T17:30:00" <container_id>

Displays logs generated since the specified date and time.


Docker Inspect

docker inspect is used to view detailed information about a container, image, network, or volume.

docker inspect <container_id>


Access a Running or Exited Container

To open a shell inside a running container:

docker exec -it <container_id> sh

  • -i = Interactive mode
  • -t = Allocate a terminal

Docker Remove

Delete an Exited Container

docker rm <container_id>

Delete a Running Container

docker rm -f <container_id>

-f forcefully stops and removes the container.

Alternative Method

First stop the container:

docker stop <container_id>

Then remove it:

docker rm <container_id>


Delete Multiple Containers

docker rm -f <container_id1> <container_id2> <container_id3>

Alternative Method (Windows)

FOR /F "tokens=*" %i IN ('docker ps -aq') DO docker rm -f %i

This command removes all containers.


Listing Containers

View Running Containers

docker ps

ps stands for Process Status.

This command lists only running containers.

View All Containers

docker ps -a

This command lists all containers, including exited containers.

-a stands for all.

View Only Container IDs

docker ps -aq

This command lists all container IDs.


Delete Images

docker rmi -f <image_id>

This command forcefully removes an image.


Naming a Container

To assign a name to a container:

docker run -d --name anyname busybox:1.36

Example:

docker run -d --name my-container busybox:1.36

This creates a container with the name my-container.