You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将.bashrc中的Docker相关函数转换为PowerShell等效实现?

PowerShell版VidHop Docker管理函数

以下是与你原有bash功能完全匹配的PowerShell函数实现:

function vidhop_stop {
    $containerIds = docker ps -a -q
    if ($containerIds) {
        docker stop $containerIds
        docker rm $containerIds
    }
}

function vidhop_start {
    # 执行stop并抑制输出
    vidhop_stop *> $null
    docker run --name vidhop-docker `
        -v "${PWD}/media:/vidhop" `
        -v "${PWD}/vidhop/.bash_history:/root/.bash_history" `
        -it vidhop-docker /bin/bash
}

function vidhop_build {
    if (-not (Test-Path -Path "Dockerfile" -PathType Leaf)) {
        Write-Host "当前目录没有Dockerfile"
        return
    }
    docker build -t vidhop-docker .
}

function vidhop_build_no_cache {
    if (-not (Test-Path -Path "Dockerfile" -PathType Leaf)) {
        Write-Host "当前目录没有Dockerfile"
        return
    }
    docker build --no-cache -t vidhop-docker .
}

function vidhop {
    param(
        [Parameter(Position=0)]
        [string]$Command
    )

    if ([string]::IsNullOrEmpty($Command)) {
        Write-Host "用法: vidhop start | stop | build"
        return
    }

    switch ($Command.ToLower()) {
        "start" { vidhop_start; return }
        "stop" { vidhop_stop; return }
        "build" { vidhop_build; return }
        default { Write-Host "'$Command' 不是有效参数,请使用 'vidhop [ start | stop | build ]'" }
    }
}

新手安装指南

临时生效(仅当前PowerShell会话可用)

  • 打开PowerShell窗口
  • 复制上述全部代码,粘贴到窗口中按回车执行
  • 直接输入vidhop start/vidhop stop等命令即可使用

永久生效(所有PowerShell会话都可用)

  1. 查看PowerShell配置文件路径,执行命令:
    $PROFILE
    
  2. 若文件不存在,创建配置文件:
    New-Item -Path $PROFILE -ItemType File -Force
    
  3. 打开配置文件进行编辑:
    notepad $PROFILE
    
  4. 将上述函数代码粘贴到文件中,保存后关闭
  5. 允许本地脚本运行(否则配置文件无法生效):
    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    
    按提示输入Y确认
  6. 重启PowerShell,之后每次打开都能直接使用这些命令

内容的提问来源于stack exchange,提问作者progonkpa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 09:00:51