Skip to content
On this page
  • docker ps 查看正在运行的容器
  • docker ps -a 查看运行过的容器
  • docker pull ubuntu:20.04 下载 ubuntu 镜像
  • docker pull myregistry.local:5000/testing/test-image:0.1 下载指定域名下的镜像
  • docker run --name test -dit alpine 由镜像得到容器(容器在后台运行),并把容器取名为 test
  • docker run alpine sh 由镜像得到容器,并运行 sh 命令(容器在当前终端运行)
  • docker run -p 9090:8080 -dit alpine 端口映射
  • docker run -e ENV1=foo -dit alpine 设置环境变量
  • docker run --network=xxx -dit alpine 设置网络
  • docker stop container_id 或 docker kill container_id 停止容器(二者区别见这里
  • docker start container_id 开始运行容器
  • docker rm container_id 删除已停止运行的容器
  • docker rm -f container_id 强制删除容器,不管有没有在运行
  • docker rm $(docker ps --filter status=exited -q) 删除所有已停止运行的容器
  • docker rmi image_id 删除镜像
  • docker system prune 删除占用硬盘的垃圾对象,包括没用的 container、images、network
  • docker image prune -a 删除所有没被用到的镜像

Released under the MIT License.