Docker基础命令

Docker 是一个开源的容器化平台,用于开发、部署和运行应用程序。以下是一些基本的 Docker 命令:

  1. 安装 Docker

    在 Linux 上,你可以使用包管理器安装 Docker,例如在 Ubuntu 上:

    bash 复制代码
    sudo apt-get update
    sudo apt-get install docker.io
  2. 启动 Docker 服务

    bash 复制代码
    sudo service docker start
  3. 检查 Docker 版本

    bash 复制代码
    docker --version
  4. 运行一个容器

    bash 复制代码
    docker run [选项] <image> [命令] [参数]

    例如,运行一个基于 nginx 的容器:

    bash 复制代码
    docker run --name my-nginx -d -p 8080:80 nginx
  5. 列出容器

    • 列出正在运行的容器:

      bash 复制代码
      docker ps
    • 列出所有容器(包括停止的):

      bash 复制代码
      docker ps -a
  6. 停止容器

    bash 复制代码
    docker stop <容器ID或名称>
  7. 启动容器

    bash 复制代码
    docker start <容器ID或名称>
  8. 删除容器

    bash 复制代码
    docker rm <容器ID或名称>
  9. 查看容器日志

    bash 复制代码
    docker logs <容器ID或名称>
  10. 进入容器

    bash 复制代码
    docker exec -it <容器ID或名称> /bin/bash
  11. 构建镜像

    bash 复制代码
    docker build -t <用户名>/<仓库名>:<tag> <路径>
  12. 推送镜像到仓库

    bash 复制代码
    docker push <用户名>/<仓库名>:<tag>
  13. 拉取镜像

    bash 复制代码
    docker pull <image>
  14. 删除镜像

    bash 复制代码
    docker rmi <镜像ID或名称>
  15. 查看镜像

    bash 复制代码
    docker images
  16. 清理未使用的资源

    • 清理未使用的容器、网络和镜像:

      bash 复制代码
      docker system prune
    • 清理所有未使用的资源(包括镜像、容器、卷和网络):

      bash 复制代码
      docker system prune -a
  17. 查看 Docker 信息

    bash 复制代码
    docker info

这些命令是 Docker 使用的基础,通过它们你可以开始创建、管理和部署容器化应用程序。记得在使用 Docker 时,需要有相应的权限或使用 sudo 命令。

相关推荐
橙*^O^*安1 小时前
Go 语言基础:变量与常量
运维·开发语言·后端·golang·kubernetes
阿拉斯加大闸蟹2 小时前
基于RDMA 通信的可负载均衡高性能服务架构
运维·架构·负载均衡
不是吧这都有重名3 小时前
为什么ubuntu大文件拷贝会先快后慢?
linux·运维·ubuntu
sunshine-sm3 小时前
CentOS Steam 9安装 Redis
linux·运维·服务器·redis·centos
Davie_Liu3 小时前
【Docker Buildx】docker buildx本地构建多架构镜像,拉取镜像时的网络延迟问题(已解决)
网络·docker·buildx
_Walli_4 小时前
k8s集群搭建(三)-------- Dashboard UI
云原生·容器·kubernetes
棒棒的唐4 小时前
armbian平台ubuntu环境下telnet安装及启动,给pantherX2增加一个应急通道
linux·运维·armbian·telnetd
纳切威4 小时前
CentOS 7部署Zabbix5.0
linux·运维·centos·zabbix
sunshine-sm5 小时前
CentOS Steam 9安装 MySQL 8
linux·运维·服务器·数据库·mysql·centos·centos stream
bug攻城狮5 小时前
CentOS 7 快速检查软件包是否已安装的5种方法
linux·运维·centos