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.

目录
相关文章
|
资源调度 负载均衡 监控
PD在TiDB集群中的角色
【2月更文挑战第28天】PD是TiDB集群的核心组件,负责元数据管理、资源调度、负载均衡和故障恢复。它保证元数据一致性,智能调度数据以实现负载均衡,快速响应故障恢复,同时提供集群监控和告警功能,确保TiDB的高性能、高可用性和稳定性。随着技术进步,PD将持续优化,提升数据库服务体验。
|
Web App开发 网络协议 缓存
DNS简明教程
在我看来,DNS(域名系统)是互联网的核心。我始终认为,控制了DNS就等于控制了网络世界。下面我们就来深入了解DNS。
754 83
DNS简明教程
|
网络协议 安全 网络安全
HTTP与HTTPS协议入门
HTTP协议是互联网的基石,HTTPS则是其安全版本。HTTP基于TCP/IP协议,属于应用层协议,不涉及数据包传输细节,主要规定客户端与服务器的通信格式,默认端口为80。
764 25
HTTP与HTTPS协议入门
|
Python 存储 自然语言处理
Langchain 和 RAG 最佳实践
这是一篇关于LangChain和RAG的快速入门文章,主要参考了由Harrison Chase和Andrew Ng讲授的​​Langchain chat with your data​​​课程。你可以在​​rag101仓库​​​中查看完整代码。本文翻译自我的英文博客,最新修订内容可随时参考:​​LangChain 与 RAG 最佳实践​​。
800 4
Langchain 和 RAG 最佳实践
|
存储 机器学习/深度学习 并行计算
一文说清IPython:新手入门指南与实用技巧
一文说清IPython:新手入门指南与实用技巧
767 0
|
编解码 固态存储 容器
视频技术入门指南
你真的理解视频技术吗?什么是帧率、分辨率、码率?它们之间有什么关系?你知道“1080p”和“4K”中的“p”和“K”代表什么吗?如何描述视频质量?蓝光光盘(Blu-ray Disc)究竟是什么?H.264/AVC、H.265/HEVC、AV1 等编解码器有什么区别?苹果的 Apple ProRes 又有什么特殊用途?HDR 和杜比视界(Dolby Vision)是什么?为什么视频文件有.mp4、.mkv、.flv 等多种后缀?
2888 0
视频技术入门指南
|
网络协议 CDN 网络安全
真正的计算机网络
本文深入浅出地介绍了计算机网络的基本概念、服务提供商(如IDC、ISP)、公共与专用网络电路、IP地址及其归属、DNS解析机制、CDN内容分发网络以及代理等相关知识。文章不仅涵盖了基础概念,还探讨了网络优化和实际应用中的常见问题,帮助读者从不同角度理解计算机网络的运作原理。更多详细内容请参阅我的博客:[Real Computer Network](https://blog.timerring.com/posts/real-computer-network/)。
632 18
|
容器 Docker Ubuntu
Docker命令速查表​
本文翻译自我的英文博客,最新修订内容可随时参考:Docker命令速查表
373 9
|
Python API 监控
将Python CLI工具发布为pip模块的完整指南
注册PyPI账户 访问PyPI官网注册账户 推荐使用双因素认证增强安全性 生成API令牌 访问PyPI账户管理 生成具有"Upload packages"权限的令牌,妥善保存 确保模块名唯一性 在PyPI搜索页面验证模块名未被使用 建议使用小写字母和连字符的组合(如my-cli-tool)
371 9
|
Python 容器
Python中的实例方法、类方法、静态方法与魔法方法
在Python中,方法的类型决定了其与类、实例的交互方式。本文将详细解析实例方法(Instance Method)、类方法(Class Method)、静态方法(Static Method)的区别,并介绍特殊的魔法方法(Magic Method和私有方法。
381 8