Docker常用指令

基础指令

  • docker run

    运行一个 ubuntu 容器并在其中执行 echo "Hello, Docker!" 命令:

    bash 复制代码
    docker run ubuntu /bin/echo "Hello, Docker!"
  • docker pull

    从 Docker Hub 下载最新的 nginx 镜像:

    bash 复制代码
    docker pull nginx
  • docker build

    在当前目录下,假设有一个 Dockerfile,构建一个名为 my-custom-app 的镜像:

    bash 复制代码
    docker build -t my-custom-app .
  • docker images

    列出本地所有的 Docker 镜像:

    bash 复制代码
    docker images
  • docker rmi

    删除名为 my-custom-app 的镜像:

    bash 复制代码
    docker rmi my-custom-app
  • docker ps

    列出所有正在运行的容器:

    bash 复制代码
    docker ps

    列出所有容器,包括未运行的:

    bash 复制代码
    docker ps -a

容器管理

  • docker start

    启动名为 my-container 的容器:

    bash 复制代码
    docker start my-container
  • docker stop

    停止名为 my-container 的容器:

    bash 复制代码
    docker stop my-container
  • docker restart

    重启名为 my-container 的容器:

    bash 复制代码
    docker restart my-container
  • docker rm

    删除名为 my-container 的容器:

    bash 复制代码
    docker rm my-container
  • docker logs

    查看名为 my-container 的容器的日志:

    bash 复制代码
    docker logs my-container
  • docker exec

    在运行中的 my-container 容器内执行 bash 命令行界面:

    bash 复制代码
    docker exec -it my-container bash

高级管理

  • docker volume create

    创建一个名为 my-volume 的新卷:

    bash 复制代码
    docker volume create my-volume
  • docker network create

    创建一个名为 my-network 的新网络:

    bash 复制代码
    docker network create my-network
  • docker compose up

    假设当前目录下有一个 docker-compose.yml 文件,启动所有服务:

    bash 复制代码
    docker-compose up

这些例子提供了在 Linux 系统下使用 Docker 命令的基础知识。实践中,根据具体需求,可能需要对命令进行调整或组合使用。

相关推荐
肖祥2 分钟前
Nginx UI - 可视化管理平台
docker·运维开发
YBCarry_段松啓7 小时前
DeerFlow单服务器低成本公网访问
docker·开源·llm
OrionZephyr7 小时前
使用watchtower更新docker容器
docker
努力买辣条15 小时前
基于 Docker 的高可用 WordPress 集群部署:分布式 Nginx + Keepalived、MySQL 主从复制与 ProxySQL 读写分离
分布式·nginx·docker
CTRA王大大19 小时前
【golang】制作linux环境+golang的Dockerfile | 如何下载golang镜像源
linux·开发语言·docker·golang
萌虎爱分享1 天前
Docker容器化部署实战:Tomcat与Nginx服务配置指南
nginx·docker·tomcat·容器部署
@寄居蟹1 天前
Docker 命令大全
docker·容器·eureka
运维开发王义杰1 天前
GitLab CI:深度解析 Runner的Shell与Docker执行器
ci/cd·docker·gitlab
qq_364371721 天前
Docker 常见命令
运维·docker·容器
照物华1 天前
k8s之 Pod 资源管理与 QoS
云原生·容器·kubernetes