docker build 报错 source: not found

FROM python:3.10.10-bullseye 
RUN . /etc/os-release && cat > /etc/apt/sources.list <

报错了

─➤  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 < 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 <

你可能感兴趣的:(docker)