Docker Cheatsheet

简介: This is a cheatsheet of docker.

The article will be updated from time to time, feel free to check the latest revision: Docker Cheatsheet

Deamon

  • docker info
  • systemctl start | stop | restart | status | enable docker This command to operate the docker daemon. For more details, you can refer to the systemd.
  • docker system df query the disk usage of the docker

images

  1. docker push <username>/<image_name>
  2. docker images
  3. docker pull | inspect | rmi ubuntu:20.04
    • normally, the image name is composed by registry/username/repository:tag, if there is no username, the default is library, which is the official repository. if there is no registry, the default is docker.io, which is the official registry.
  4. docker create -it ubuntu:20.04 create a container by the image
  5. docker tag image_name:tag new_image_name:new_tag
  6. docker export/import and docker save/load
    • export/import will discard history and metadata information, only saving the snapshot state of the container at the time
      • docker export -o xxx.tar CONTAINER
      • docker import xxx.tar image_name:tag
    • save/load will save the complete record, with a larger volume
      • docker save -o xxx.tar image_name:tag
      • docker load -i xxx.tar

docker hub

  1. docker login -u <username>
  2. docker search <image_name>
  3. docker push <username>/<image_name>
  4. dangling image: if the image is updated by official, and the tag is allocated to the new image, the old image will be called dangling image. Only display <none> in the docker images command.

containers

  • docker ps -a list all containers
  • docker ps list running containers
  • docker stats search all the containers resource usage (CPU, memory, storage, network)
  • docker rename CONTAINER1 CONTAINER2
  • docker start | stop | restart | rm | top | inspect | kill | port | history CONTAINER
  • docker run -itd ubuntu:20.04 search and run a container (-d means detach) == pull + create + start
    • eg. docker run -p 20000:22 --name my_docker_server -itd docker_images:1.0
  • docker attach CONTAINER
    • ⌃ + p and ⌃ + q which can detach the container
    • ⌃+d which can close and exit the container(exit; then the container will be stopped)
  • docker logs -f CONTAINER -f means follow, you can see the logs in real time
  • docker cp xxx CONTAINER:xxx
  • docker exec CONTAINER COMMAND
    • eg docker exec -it container_name bash
    • docker exec -it container_name /bin/bash if your garrison program is sshd(which is not accept input) not the bash, then you should use this command to substitute it. (Recommend, exit; the container will not be stopped)
    • You can also use docker run -it container_name /bin/bash specific the shell to enter the container.
  • docker update CONTAINER --memory 500MB
  • docker container prune remove all stopped containers
  • docker commit container_name image_name:tag Package the container as an image.(Not recommend use to build image, can use as a snapshot of the container)

Docker volume

The volume will not be deleted when the container is deleted. Volume can be shared between containers.

  • docker volume create VOLUME create a volume
    • docker run --mount source=VOLUME,target=/webapp option to specify the volume
  • docker volume ls list all volumes
  • docker volume rm VOLUME remove the volume
  • docker volume prune remove all unused volumes
  • docker volume inspect VOLUME inspect the volume
  • docker rm -v CONTAINER remove the container and the volume

Besides, you can also mount the host directory to the container. The host directory path must be absolute path.

docker run -d -P \
    --name web \
    --mount type=bind,source=/src/webapp,target=/opt/webapp[,readonly] \
    training/webapp \
    python app.py

For the detail of build docker image, you can refer to the tips about dockerfile.

目录
相关文章
|
8月前
|
Web App开发 网络协议 缓存
DNS简明教程
在我看来,DNS(域名系统)是互联网的核心。我始终认为,控制了DNS就等于控制了网络世界。下面我们就来深入了解DNS。
362 83
DNS简明教程
|
6月前
|
Python 存储 自然语言处理
Langchain 和 RAG 最佳实践
这是一篇关于LangChain和RAG的快速入门文章,主要参考了由Harrison Chase和Andrew Ng讲授的​​Langchain chat with your data​​​课程。你可以在​​rag101仓库​​​中查看完整代码。本文翻译自我的英文博客,最新修订内容可随时参考:​​LangChain 与 RAG 最佳实践​​。
250 4
Langchain 和 RAG 最佳实践
|
7月前
|
网络协议 安全 网络安全
HTTP与HTTPS协议入门
HTTP协议是互联网的基石,HTTPS则是其安全版本。HTTP基于TCP/IP协议,属于应用层协议,不涉及数据包传输细节,主要规定客户端与服务器的通信格式,默认端口为80。
232 25
HTTP与HTTPS协议入门
|
7月前
|
应用服务中间件 Linux nginx
部署使用 CHAT-NEXT-WEB 基于 Deepseek
本文介绍如何在阿里云轻量服务器上部署基于 `Deepseek` 的 `CHAT-NEXT-WEB` 项目。首先,准备一台 Linux 服务器并安装 Docker,确保防火墙允许特定端口访问。接着,通过阿里云容器镜像服务解决国内网络限制问题,将镜像推送到私有仓库并拉取到本地。配置并启动 `chat-next` 项目,使用 Deepseek API 进行优化。最后,安装 Nginx 和 Certbot 配置 HTTPS 访问,确保安全性和自动续签。整个过程需严格遵循官方文档,以避免因网络问题导致的安装失败。
|
8月前
|
网络协议 CDN 网络安全
真正的计算机网络
本文深入浅出地介绍了计算机网络的基本概念、服务提供商(如IDC、ISP)、公共与专用网络电路、IP地址及其归属、DNS解析机制、CDN内容分发网络以及代理等相关知识。文章不仅涵盖了基础概念,还探讨了网络优化和实际应用中的常见问题,帮助读者从不同角度理解计算机网络的运作原理。更多详细内容请参阅我的博客:[Real Computer Network](https://blog.timerring.com/posts/real-computer-network/)。
268 18
|
7月前
|
Python 容器
Python中的实例方法、类方法、静态方法与魔法方法
在Python中,方法的类型决定了其与类、实例的交互方式。本文将详细解析实例方法(Instance Method)、类方法(Class Method)、静态方法(Static Method)的区别,并介绍特殊的魔法方法(Magic Method和私有方法。
143 8
|
7月前
|
编解码 固态存储 容器
视频技术入门指南
你真的理解视频技术吗?什么是帧率、分辨率、码率?它们之间有什么关系?你知道“1080p”和“4K”中的“p”和“K”代表什么吗?如何描述视频质量?蓝光光盘(Blu-ray Disc)究竟是什么?H.264/AVC、H.265/HEVC、AV1 等编解码器有什么区别?苹果的 Apple ProRes 又有什么特殊用途?HDR 和杜比视界(Dolby Vision)是什么?为什么视频文件有.mp4、.mkv、.flv 等多种后缀?
547 0
视频技术入门指南
|
8月前
|
虚拟化 Docker 容器
DockerHub被禁掉的应对之法
在DockerHub被禁用或访问受限的情况下,可以选择使用其他公共镜像仓库、本地私有镜像仓库或镜像加速器。这些替代方案不仅能够保证容器化应用的正常运行,还可以根据具体需求提供不同的功能和服务。确保按照文档和指南进行配置,以实现最佳效果和性能。
1943 21
|
8月前
|
开发工具 数据安全/隐私保护 git
GPG 101
本文介绍了GPG(GnuPG)的基本使用方法,GPG是OpenPGP标准的完整免费实现,支持数据加密和签名。文章涵盖GPG的基础概念、安装、密钥生成与管理、导出与导入、签名与验证、加密与解密以及Git配置等内容。特别提醒不要上传任何信息到公共密钥服务器,以免造成安全隐患。更多详细内容请参考我的博客:[gpg-101](https://blog.timerring.com/posts/gpg-101)。
221 6
|
监控 前端开发 JavaScript
Sentry 监控部署与使用(详细流程)
Sentry 监控部署与使用(详细流程)
2178 0