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

本地运行正常但SSH服务器执行脚本时提示docker: command not found问题求助

Fixing "docker: command not found" When Running Scripts Over SSH on a Server

Hey there, let's figure out why you're hitting this error and get it sorted out quickly. The core issue here is that your local MacBook Pro's Docker setup doesn't translate to the remote server you're SSHing into—these are two completely separate environments, so what works locally won't automatically work on the server.

Let's break down the problem and the fixes step by step:

Why This Happens

  • Your local Docker Desktop is installed on your Mac, but the remote server has no idea about it—unless you explicitly install Docker on the server, the system won't recognize the docker command.
  • The pip3 install docker command you ran only installs the Python Docker SDK, which lets you interact with a Docker engine via Python code. It does NOT install the actual Docker CLI or engine itself—so even with this SDK, you still need Docker installed on the server to run docker commands.

Step-by-Step Fixes

1. Install Docker on the Remote Server

First, confirm Docker isn't already installed by running this in your SSH session:

docker --version

If you get the "command not found" error, install Docker based on your server's OS:

For Debian/Ubuntu-based servers:

sudo apt update
sudo apt install docker.io -y

For RHEL/CentOS/Rocky Linux-based servers:

sudo dnf install docker -y
sudo systemctl start docker
sudo systemctl enable docker

After installation, run docker --version again to verify it's working.

By default, Docker requires root privileges to run. To avoid typing sudo every time, add your user to the docker group:

sudo usermod -aG docker $USER

Log out of your SSH session and log back in for this change to take effect.

3. Check Docker's Path in the Server's Environment

Sometimes the Docker CLI path isn't included in the server's PATH variable. Find where Docker is installed with:

which docker

You'll get a path like /usr/bin/docker. If this path isn't in your PATH, you can:

  • Add it to your shell config (e.g., ~/.bashrc or ~/.zshrc):
    echo 'export PATH=$PATH:/usr/bin/docker' >> ~/.bashrc
    source ~/.bashrc
    
  • Or, update your script to use the full path instead of just docker (e.g., replace docker run ... with /usr/bin/docker run ...).

4. Ensure Docker Service is Running on the Server

Double-check that the Docker service is active:

sudo systemctl status docker

If it's not running, start it with:

sudo systemctl start docker

And set it to start automatically on boot:

sudo systemctl enable docker

Once you've gone through these steps, try running your ./name.sh script again—it should recognize the docker command now.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 21:09:06