GitRead 中文社区
首页趋势排行榜原创文章严选周刊
更多资源
新手训练营
精选专题热门话题GitHub 文档资源精选实战指南

DockerCheatSheet

🐋Docker Cheat Sheet

  • 默认分支master
  • 大小114 KB
  • 更新2月19日
  • Issues4
在 GitHub 打开
avatareon01

项目介绍

eon01/DockerCheatSheet 是一个托管在 GitHub 上的开源项目,采用 MIT License 许可证,目前获得 4.0k 个 Star、479 次 Fork。

仓库全名
eon01/DockerCheatSheet

README 摘要

This repository has been trending on GitHub. I appreciate your support. Work adapted from Painless Docker (2nd edition). Read this in other languages: English, Russian, Persian, Chinese Table of Contents Installation Docker Registries & Repositories Running Containers Starting & Stopping Containers Getting Information about Containers Networking Security Cleaning Docker Docker Swarm Docker Compose Useful…

完整内容见 GitHub 原始 README 或本页 。

常见问题

DockerCheatSheet 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 DockerCheatSheet 的源码?

可以直接克隆仓库:git clone https://github.com/eon01/DockerCheatSheet.git,默认分支为 master;安装与运行步骤见仓库 README。

DockerCheatSheet 最近还在维护吗?

仓库最近一次更新为 2月19日,当前有 4 个未关闭 Issue;Star 数为 4.0k,可作为社区活跃度的参考。

本页面展示项目元数据与原始 README,GitRead 中文社区 编辑团队负责选题收录。

相关仓库

codecrafters-io/build-your-own-x avatar
build-your-own-xcodecrafters-io
1 天前
561.5k
52.5k
693

通过从零复刻你最喜欢的技术来精通编程。

awesome-listfreeprogramming+3
Markdown
1.1 MB
10
详情
sindresorhus/awesome avatar
awesomesindresorhus
9月2日
534.5k
37.1k
16

关于各种有趣主题的精选列表 [注意:在我有机会处理现有拉取请求之前,拉取请求暂时禁用]

awesomeawesome-listlists+2
未知
1.5 MB
1
详情
public-apis/public-apis avatar
public-apispublic-apis
2 天前
497.8k
55.7k
2.6k

免费 API 汇总列表

apipublic-apisfree+7
Python
15.5 MB
7
详情
freeCodeCamp/freeCodeCamp avatar
freeCodeCampfreeCodeCamp
2 小时前
458.8k
47.4k
193

freeCodeCamp.org 的开源代码库和课程体系。免费学习数学、编程和计算机科学。

learn-to-codenonprofitsprogramming+7
TypeScript
571.3 MB
9
详情
morluto/rea avatar
reamorluto
24 分钟前
448.4k
110.5k
1.7k

借助智能体逆向分析任何内容,从应用行为直至原生二进制文件。

agent-skillsaiandroid+17
TypeScript
147.1 MB
0
详情
EbookFoundation/free-programming-books avatar
free-programming-booksEbookFoundation
2 天前
401.4k
67.5k
94

免费可获取的编程书籍

bookseducationhacktoberfest+2
Python
21.8 MB
3
详情
openclaw/openclaw avatar
openclawopenclaw
20 分钟前
394.3k
82.9k
8.1k

真正做实事的 AI。任何 OS。任何平台。龙虾之道。🦞

aiassistantown-your-data+4
TypeScript
13.1 GB
18
详情
donnemartin/system-design-primer avatar
system-design-primerdonnemartin
9月15日
377.5k
57.4k
291

学习如何设计大规模系统。为系统设计面试做准备。包含 Anki 闪卡。

designdesign-patternsdesign-system+10
Python
11.0 MB
0
详情

关于

bookscleaning-dockercoursedockerdocker-composedocker-containerdocker-imagedocker-registriesdocker-registrydocker-swarmdockerfilesregistryswarmvolume
  • MIT License
  • 4.0k Stars
  • 479 Forks
  • 127 Watching

简要分析

热度分
5038
价值分
2527
活跃状态
活跃
GitHub

贡献者

eon01eon01elias8702elias8702kevin-mengkevin-mengsolodyaginsolodyaginrhzsrhzsmetonymic-smokeymetonymic-smokeymilewskimilewskiiron0012iron0012woernflwoernflflaviohelenoflaviohelenohimanshudashimanshudasvania-poohvania-pooh

This repository has been trending on GitHub. I appreciate your support.

Work adapted from Painless Docker (2nd edition).

Read this in other languages: English, Russian, Persian, Chinese

Table of Contents

  • Installation
  • Docker Registries & Repositories
  • Running Containers
  • Starting & Stopping Containers
  • Getting Information about Containers
  • Networking
  • Security
  • Cleaning Docker
  • Docker Swarm
  • Docker Compose
  • Useful Commands
  • Notes

The Ultimate Docker Cheat Sheet

Installation

Linux

For more information, see here

curl -sSL https://get.docker.com/ | sh

Mac

For more information, see here

Use this link to download the dmg.

https://download.docker.com/mac/stable/Docker.dmg

Open the downloaded file and follow the installation instructions.

Windows

For more information, see here

Use the msi installer:

https://download.docker.com/win/stable/InstallDocker.msi

Open the downloaded file and follow the installation instructions.

Docker Registries & Repositories

Login to a Registry

docker login
docker login localhost:8080

Logout from a Registry.

docker logout
docker logout localhost:8080

Searching an Image

docker search nginx
docker search --filter stars=3 --no-trunc nginx

Pulling an Image

docker image pull nginx
docker image pull eon01/nginx localhost:5000/myadmin/nginx

Pushing an Image

docker image push eon01/nginx
docker image push eon01/nginx localhost:5000/myadmin/nginx

Running Containers

Create and Run a Simple Container

-Start an ubuntu:latest image

  • Bind the port 80 from the CONTAINER to port 3000 on the HOST
  • Mount the current directory to /data on the CONTAINER
  • Note: on windows you have to change -v ${PWD}:/data to -v "C:\Data":/data
docker container run --name infinite -it -p 3000:80 -v ${PWD}:/data ubuntu:latest

Creating a Container

docker container create -t -i eon01/infinite --name infinite

Running a Container

docker container run -it --name infinite -d eon01/infinite

Renaming a Container

docker container rename infinite infinity

Removing a Container

docker container rm infinite

A container can be removed only after stopping it using docker stop command. To avoid this, add the --rm flag while running the container.

Updating a Container

docker container update --cpu-shares 512 -m 300M infinite

Running a command within a running container

docker exec -it infinite sh

In the example above, bash can replace sh as an alternative (if the above is giving an error).

Starting & Stopping Containers

Starting

docker container start nginx

Stopping

docker container stop nginx

Restarting

docker container restart nginx

Pausing

docker container pause nginx

Unpausing

docker container unpause nginx

Blocking a Container

docker container wait nginx

Sending a SIGKILL

docker container kill nginx

Sending another signal

docker container kill -s HUP nginx

Connecting to an Existing Container

docker container attach nginx

Getting Information about Containers

From Running Containers

Shortest way:

docker ps

Alternative:

docker container ls

From All containers.

docker ps -a
docker container ls -a

Container Logs

docker logs infinite

‘tail -f’ Containers’ Logs

docker container logs infinite -f

Inspecting Containers

docker container inspect infinite
docker container inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q)

Containers Events

docker system events infinite

Public Ports

docker container port infinite

Running Processes

docker container top infinite

Container Resource Usage

docker container stats infinite

Inspecting changes to files or directories on a container’s filesystem

docker container diff infinite

Managing Images

Listing Images

docker image ls

Building Images

From a Dockerfile in the Current Directory

docker build .

From a Remote GIT Repository

docker build github.com/creack/docker-firefox

Instead of Specifying a Context, You Can Pass a Single Dockerfile in the URL or Pipe the File in via STDIN

docker build - < Dockerfile
docker build - < context.tar.gz

Building and Tagging

docker build -t eon/infinite .

Building a Dockerfile while Specifying the Build Context

docker build -f myOtherDockerfile .

Building from a Remote Dockerfile URI

curl example.com/remote/Dockerfile | docker build -f - .

Removing an Image

docker image rm nginx

Loading a Tarred Repository from a File or the Standard Input Stream

docker image load < ubuntu.tar.gz
docker image load --input ubuntu.tar

Saving an Image to a Tar Archive

docker image save busybox > ubuntu.tar

Showing the History of an Image

docker image history

Creating an Image From a Container

docker container commit nginx

Tagging an Image

docker image tag nginx eon01/nginx

Pushing an Image

docker image push eon01/nginx

Networking

Creating Networks

Creating an Overlay Network

docker network create -d overlay MyOverlayNetwork

Creating a Bridge Network

docker network create -d bridge MyBridgeNetwork

Creating a Customized Overlay Network

docker network create -d overlay \
  --subnet=192.168.0.0/16 \
  --subnet=192.170.0.0/16 \
  --gateway=192.168.0.100 \
  --gateway=192.170.0.100 \
  --ip-range=192.168.1.0/24 \
  --aux-address="my-router=192.168.1.5" --aux-address="my-switch=192.168.1.6" \
  --aux-address="my-printer=192.170.1.5" --aux-address="my-nas=192.170.1.6" \
  MyOverlayNetwork

Removing a Network

docker network rm MyOverlayNetwork

Listing Networks

docker network ls

Getting Information About a Network

docker network inspect MyOverlayNetwork

Connecting a Running Container to a Network

docker network connect MyOverlayNetwork nginx

Connecting a Container to a Network When it Starts

docker container run -it -d --network=MyOverlayNetwork nginx

Disconnecting a Container from a Network

docker network disconnect MyOverlayNetwork nginx

Exposing Ports

Using Dockerfile, you can expose a port on the container using:

EXPOSE <port_number>

You can also map the container port to a host port using:

docker run -p $HOST_PORT:$CONTAINER_PORT --name <container_name> -t <image>

e.g.

docker run -p $HOST_PORT:$CONTAINER_PORT --name infinite -t infinite

Security

Guidelines for building secure Docker images

  1. Prefer minimal base images
  2. Dedicated user on the image as the least privileged user
  3. Sign and verify images to mitigate MITM attacks
  4. Find, fix and monitor for open source vulnerabilities
  5. Don’t leak sensitive information to docker images
  6. Use fixed tags for immutability
  7. Use COPY instead of ADD
  8. Use labels for metadata
  9. Use multi-stage builds for small secure images
  10. Use a linter

You can find more nformation on Snyk’s 10 Docker Image Security Best Practices blog post.

Cleaning Docker

Removing a Running Container

docker container rm nginx

Removing a Container and its Volume

docker container rm -v nginx

Removing all Exited Containers

docker container rm $(docker container ls -a -f status=exited -q)

Removing All Stopped Containers

docker container rm `docker container ls -a -q`

Removing a Docker Image

docker image rm nginx

Removing Dangling Images

docker image rm $(docker image ls -f dangling=true -q)

Removing all Images

docker image rm $(docker image ls -a -q)

Removing all Untagged Images

docker image rm -f $(docker image ls | grep "^<none>" | awk "{print $3}")

Stopping & Removing all Containers

docker container stop $(docker container ls -a -q) && docker container rm $(docker container ls -a -q)

Removing Dangling Volumes

docker volume rm $(docker volume ls -f dangling=true -q)

Removing all unused (containers, images, networks and volumes)

docker system prune -f

Clean all

docker system prune -a

Docker Swarm

Installing Docker Swarm

curl -ssl https://get.docker.com | bash

Initializing the Swarm

docker swarm init --advertise-addr 192.168.10.1

Getting a Worker to Join the Swarm

docker swarm join-token worker

Getting a Manager to Join the Swarm

docker swarm join-token manager

Listing Services

docker service ls

Listing nodes

docker node ls

Creating a Service

docker service create --name vote -p 8080:80 instavote/vote

Listing Swarm Tasks

docker service ps

Scaling a Service

docker service scale vote=3

Updating a Service

docker service update --image instavote/vote:movies vote
docker service update --force --update-parallelism 1 --update-delay 30s nginx
docker service update --update-parallelism 5--update-delay 2s --image instavote/vote:indent vote
docker service update --limit-cpu 2 nginx
docker service update --replicas=5 nginx

Docker Compose

docker compose up -d              # Start services in background
docker compose down               # Stop and remove containers
docker compose down -v            # Stop and remove containers + volumes
docker compose logs -f            # Follow logs
docker compose ps                 # List running services
docker compose exec app sh        # Execute shell in service
docker compose build --no-cache   # Rebuild without cache

Useful Commands

Copy files between container and host

docker cp container:/path/file /host/path
docker cp /host/path container:/path/file

View resource usage

docker stats
docker system df

Get container IP

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name

Run as specific user

docker exec -u root -it container_name sh

Quick cleanup

docker system prune -a --volumes  # Remove all unused data

评论

登录 后发表评论
暂无评论
GitRead 中文社区
深度解读 · 趋势洞察 · 价值精选

关于

关于我们联系我们编辑准则收录标准赞赏人员

发现

技术趋势新手训练营资源精选实战指南精选专题热门话题GitHub 文档

条款

隐私政策服务条款网站地图
26.9万收录项目
5.7万中文话题
155精选专题
发现技术价值,连接开源智慧
© 2026 GitRead · GitHub 中文社区 本站与 GitHub, Inc. 无隶属关系;GitHub 是 GitHub, Inc. 的商标。