FROM python:3.10.10-bullseye
RUN . /etc/os-release && cat > /etc/apt/sources.list <<EOF
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${VERSION_CODENAME} main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${VERSION_CODENAME}-updates main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${VERSION_CODENAME}-backports main contrib non-free
deb http://security.debian.org/debian-security bullseye-security main contrib non-free
EOF
RUN apt-get update
RUN apt-get install -y vim
RUN mkdir /code
ADD . /code/
WORKDIR /code/PyAV
RUN source scripts/activate.sh && pip install --upgrade -r tests/requirements.txt && ./scripts/build-deps && make
报错了
─➤ docker build -t ponponon/pyav:0.0.1 . 2 ↵
[+] Building 3.6s (12/12) FINISHED docker:default
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 753B 0.0s
=> [internal] load metadata for docker.io/library/python:3.10.10-bullseye 0.0s
=> [1/8] FROM docker.io/library/python:3.10.10-bullseye 0.0s
=> [internal] load build context 0.5s
=> => transferring context: 3.18MB 0.5s
=> CACHED [2/8] RUN . /etc/os-release && cat > /etc/apt/sources.list <<EOF 0.0s
=> CACHED [3/8] RUN apt-get update 0.0s
=> CACHED [4/8] RUN apt-get install -y vim 0.0s
=> CACHED [5/8] RUN mkdir /code 0.0s
=> [6/8] ADD . /code/ 2.7s
=> [7/8] WORKDIR /code/PyAV 0.0s
=> ERROR [8/8] RUN source scripts/activate.sh && pip install --upgrade -r tests/requirements.txt && ./scripts/build-deps && make 0.3s
------
> [8/8] RUN source scripts/activate.sh && pip install --upgrade -r tests/requirements.txt && ./scripts/build-deps && make:
0.273 /bin/sh: 1: source: not found
------
Dockerfile:18
--------------------
16 | WORKDIR /code/PyAV
17 | CMD ["/bin/bash"]
18 | >>> RUN source scripts/activate.sh && pip install --upgrade -r tests/requirements.txt && ./scripts/build-deps && make
19 |
--------------------
ERROR: failed to solve: process "/bin/sh -c source scripts/activate.sh && pip install --upgrade -r tests/requirements.txt && ./scripts/build-deps && make" did not complete successfully: exit code: 127
问题原因,docker build 默认使用 sh,而不是 bash
而 sh 是没有 source 命令的
所以,解决方案就是把 sh 改成 bash
怎么改?加一行 SHELL ["/bin/bash", "-c"]
完整的
FROM python:3.10.10-bullseye
RUN . /etc/os-release && cat > /etc/apt/sources.list <<EOF
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${VERSION_CODENAME} main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${VERSION_CODENAME}-updates main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${VERSION_CODENAME}-backports main contrib non-free
deb http://security.debian.org/debian-security bullseye-security main contrib non-free
EOF
RUN apt-get update
RUN apt-get install -y vim
RUN mkdir /code
ADD . /code/
WORKDIR /code/PyAV
SHELL ["/bin/bash", "-c"]
RUN source scripts/activate.sh && pip install --upgrade -r tests/requirements.txt && ./scripts/build-deps && make
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。