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

Docker Compose启动报错:无法找到python可执行文件求助

问题:Docker Compose启动容器提示找不到Python可执行文件

报错信息

failed to create shim task: OCI runtime create failed:unable to start container process: exec: "python": executable file not found in $PATH: unknown

现有配置

Dockerfile(docker/Dockerfile-chap3)

FROM snisioi/retele:2021

LABEL org.opencontainers.image.authors="Sergiu Nisioi <sergiu.nisioi@fmi.unibuc.ro>"

USER root

RUN apt-get update && apt-get install -y iptables iproute2
RUN apt-get update && apt-get install -y libnetfilter-queue-dev
RUN apt-get update && apt-get install -y iperf3 moreutils 
RUN apt-get update && apt-get install -y python

COPY src/*.sh /
COPY src/examples/tcp_server.py /

CMD ["python", "tcp_server.py"]

docker-compose.yml 容器配置

server:
        build:
          context: .
          dockerfile: docker/Dockerfile-chap3
        volumes:
          - ../capitolul3:/app/src
        command: python /app/src/examples/tcp_server.py 0.0.0.0


client:
        build:
            context: .
            dockerfile: docker/Dockerfile-chap3
        volumes:
            - ../capitolul3:/app/src
        tty: true
        cap_add:
          - NET_ADMIN
          - NET_RAW
          - SYS_ADMIN
        networks:
            subnet1:
              ipv4_address: 172.10.0.2
        depends_on:
            - "router"
            - "server"
        sysctls:
          - net.ipv4.tcp_congestion_control=reno
        command: python /app/src/examples/tcp_handshake.py server 0.0.0.0

解决方案

1. 修正Dockerfile,确保Python3可用

基础镜像snisioi/retele:2021基于Debian 11+,这类系统中python包默认对应Python2(已被弃用,未正确加入PATH),需安装Python3并建立软链接:

修改Dockerfile中的Python安装命令:

# 替换原python安装行
RUN apt-get update && apt-get install -y python3 python3-pip && ln -s /usr/bin/python3 /usr/bin/python

同步更新CMD命令(可选,若已建立软链接可忽略):

CMD ["python3", "tcp_server.py"]

2. 同步docker-compose.yml中的命令

将command字段里的python替换为python3,确保和容器内可执行文件一致:

# server容器
command: python3 /app/src/examples/tcp_server.py 0.0.0.0

# client容器
command: python3 /app/src/examples/tcp_handshake.py server 0.0.0.0

3. 清理缓存重新构建

避免旧构建缓存干扰,执行:

docker-compose build --no-cache

4. 验证Python路径(可选)

若仍有问题,可在Dockerfile中添加验证步骤,确认Python路径:

RUN which python3 && which python

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 04:35:06