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.

目录
相关文章
|
存储 NoSQL 人机交互
【Docker系列】从头学起 Docker——docker --help命令详解
【Docker系列】从头学起 Docker——docker --help命令详解
【Docker系列】从头学起 Docker——docker --help命令详解
|
网络协议 应用服务中间件 Shell
【Docker系列】从头学起 Docker——docker run 命令详解
【Docker系列】从头学起 Docker——docker run 命令详解
【Docker系列】从头学起 Docker——docker run 命令详解
|
Docker 容器 Ubuntu
《第一本Docker书(修订版)》——2.7 Docker安装脚本
还有另外一种方法,就是使用远程安装脚本在相应的宿主机上安装Docker。可以从get.docker.com网站获取这个安装脚本。
1933 0
|
Ubuntu NoSQL Linux
一文讲明Docker的基本使用,常见Docker命令使用 、Docker的安装使用等
1、Docker的基本概念 2、常用的Docker命令 3、虚拟机安装Docker
|
应用服务中间件 nginx Docker
【Docker系列】从头学起 Docker——docker start 命令详解
【Docker系列】从头学起 Docker——docker start 命令详解
【Docker系列】从头学起 Docker——docker start 命令详解
|
Linux Docker 容器
【三、Docker 命令大全】
*Docker是怎么工作的** - Docker是一个Client-Server结构的系统,Docker的守护进程运行在主机上,通过Socket从客户端访问! - Docker Server接收到Docker-Client的指令,就会执行这个指令!
167 0
【三、Docker 命令大全】
|
Shell Docker 容器
Docker(一) 常用命令大全
Docker(一) 常用命令大全
183 1
|
9月前
|
Docker 容器
docker命令大全
docker命令大全
61 0
|
Ubuntu NoSQL 关系型数据库
Docker常用命令大全
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux或Windows操作系统的机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。
503 0
Docker常用命令大全
|
应用服务中间件 Shell nginx
Docker命令大全
Docker命令大全
95 1