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.

目录
相关文章
|
Java 关系型数据库 MySQL
Spring Boot实现第一次启动时自动初始化数据库
在现在的后端开发中,只要是使用关系型数据库,相信SSM架构(Spring Boot + MyBatis)已经成为首选。 不过在我们第一次运行或者部署项目的时候,通常要先手动连接数据库,执行一个SQL文件以创建数据库以及数据库表格完成数据库的初始化工作,这样我们的SSM应用程序才能够正常工作。 这样也对实际部署或者是容器化造成了一些麻烦,必须先手动初始化数据库再启动应用程序。 那能不能让我们的SSM应用程序第一次启动时,自动地帮我们执行SQL文件以完成数据库初始化工作呢? 这样事实上是没问题的,今天就以Spring Boot + MyBatis为例,使用MySQL作为数据库,完成上述的数
|
9月前
|
SQL Java 索引
IDEA 2026.1 重磅更新:Java 开发效率翻倍的核心新特性全拆解
IDEA 2026.1重磅发布:启动/索引/内存全面优化,冷启提速40%、热启秒开;原生支持JDK 17–23,深度集成虚拟线程调试与重构;AI辅助编码、MyBatis XML一键转MP、分布式链路调试、K8s原生集成,Java开发效率跃升新高度。
1903 1
|
3月前
|
人工智能 安全 搜索推荐
人气爆棚!2026 云栖大会“AI Agent 原生操作系统”分论坛精彩回顾来啦
线下展区人潮涌动,超千人参与互动,分论坛现场座无虚席。
|
9月前
|
Kubernetes Cloud Native Go
go语言快速入门指南教程
Go语言是Google推出的高性能开源编程语言,语法简洁(仅25个关键字)、编译极快、原生支持高并发(goroutine+channel),兼具C的效率与Python的开发体验。广泛用于云原生(K8s/Docker)、微服务及高并发系统。入门推荐访问golangdev.cn系统学习,再通过GitHub项目实战巩固。
1524 9
|
9月前
|
缓存 JavaScript 前端开发
Bun.js:四大核心功能 + 性能对比 + 实战教程,新手也能快速上手
Bun.js 是一款高性能、一体化的 JavaScript/TypeScript 工具链,集运行时、包管理器、打包器、测试器于一身,启动快、配置简、兼容 Node.js,支持 TS/JSX 零配置运行。适合新项目、性能敏感型应用及 TypeScript 全栈开发。(239字)
1716 1
|
JSON API 数据格式
小红书API接口文档:笔记详情数据开发手册
小红书笔记详情API可获取指定笔记的标题、正文、互动数据及多媒体资源,支持字段筛选与评论加载。通过note_id和access_token发起GET/POST请求,配合签名验证,广泛用于内容分析与营销优化。
2399 3
|
XML JSON 前端开发
bpmn.js 使用常见问题(不定时持续更新)
bpmn.js 使用常见问题(不定时持续更新)
7349 2
|
人工智能 Java API
阿里云开源 AI 应用开发框架:Spring AI Alibaba
近期,阿里云重磅发布了首款面向 Java 开发者的开源 AI 应用开发框架:Spring AI Alibaba(项目 Github 仓库地址:alibaba/spring-ai-alibaba),Spring AI Alibaba 项目基于 Spring AI 构建,是阿里云通义系列模型及服务在 Java AI 应用开发领域的最佳实践,提供高层次的 AI API 抽象与云原生基础设施集成方案,帮助开发者快速构建 AI 应用。本文将详细介绍 Spring AI Alibaba 的核心特性,并通过「智能机票助手」的示例直观的展示 Spring AI Alibaba 开发 AI 应用的便利性。示例源
14415 145
|
人工智能 开发框架 Java
重磅发布!AI 驱动的 Java 开发框架:Spring AI Alibaba
随着生成式 AI 的快速发展,基于 AI 开发框架构建 AI 应用的诉求迅速增长,涌现出了包括 LangChain、LlamaIndex 等开发框架,但大部分框架只提供了 Python 语言的实现。但这些开发框架对于国内习惯了 Spring 开发范式的 Java 开发者而言,并非十分友好和丝滑。因此,我们基于 Spring AI 发布并快速演进 Spring AI Alibaba,通过提供一种方便的 API 抽象,帮助 Java 开发者简化 AI 应用的开发。同时,提供了完整的开源配套,包括可观测、网关、消息队列、配置中心等。
12149 141