软件包安装在 docker 中,但实际命令提供异常
Package is installed inside docker but actual command provide exception
我正在尝试在 .net 6 dockerized 项目中使用 ffmpeg 核心包。我在 Docker 文件中安装 ffmpeg 核心,在解决方案中引用实际包 FFMpegCore 但是当我尝试应用 ffmpeg 核心库中的任何命令时,我收到错误
An error occurred trying to start process './ffmpeg' with working
directory '/var/task'. No such file or directory
Docker 构建完成,没有错误。
Docker文件
FROM public.ecr.aws/lambda/dotnet:6 AS base
....
RUN apt-get install -y ffmpeg
....
FROM base AS final
WORKDIR /var/task
COPY --from=publish /app/publish .
根据 ffmpeg core 文档为了使用 ffmpeg 我需要设置它的二进制文件夹,所以我添加 ffmpeg.config.json
{
"BinaryFolder": "/var/task",
"TemporaryFilesFolder": "/tmp"
}
当我尝试执行以下命令时抛出实际错误
An error occurred trying to start process './ffmpeg' with working
directory '/var/task'. No such file or directory
这是触发错误的地方
using FFMpegCore;
...
public class MyController : ControllerBase
{
public async Task<string> Get()
{
await FFMpegArguments
.FromPipeInput(new StreamPipeSource(myfile))
.OutputToPipe(new StreamPipeSink(outputStream), options => options
.WithVideoCodec("vp9")
.ForceFormat("webm"))
.ProcessAsynchronously();
...
}
}
更新:
将 BinaryFolder
位置更改为 /usr/bin
后,出现以下错误
An error occurred trying to start process '/usr/bin/ffmpeg' with working directory '/var/task'. No such file or directory
更新#2
这是我完整的Docker文件
FROM public.ecr.aws/lambda/dotnet:6 AS base
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
WORKDIR /src
COPY ["AWSServerless.csproj", "AWSServerless/"]
RUN dotnet restore "AWSServerless/AWSServerless.csproj"
WORKDIR "/src/AWSServerless"
COPY . .
RUN dotnet build "AWSServerless.csproj" --configuration Release --output /app/build
FROM build AS publish
RUN apt-get update \
&& apt-get install -y apt-utils libgdiplus libc6-dev \
&& apt-get install -y ffmpeg
RUN dotnet publish "AWSServerless.csproj" \
--configuration Release \
--runtime linux-x64 \
--self-contained false \
--output /app/publish \
-p:PublishReadyToRun=true
FROM base AS final
WORKDIR /var/task
CMD ["AWSServerless::AWSServerless.LambdaEntryPoint::FunctionHandlerAsync"]
COPY --from=publish /app/publish .
你告诉它二进制文件在 ffmpeg.config.json
中的 /var/task
中,但是 apt-get install -y ffmpeg
在 /usr/bin
中安装 ffmpeg。将 BinaryFolder
配置值更改为这样的
{
"BinaryFolder": "/usr/bin",
"TemporaryFilesFolder": "/tmp"
}
您还需要将 ffmpeg
安装在 Dockerfile 中最终映像中的某个位置。现在您将它安装在 Dockerfile 的 build/publish 部分,该部分未用于最终图像。
试试这个
FROM public.ecr.aws/lambda/dotnet:6 AS base
# Install ffmpeg
RUN mkdir /ffmpeg && \
cd /ffmpeg && \
yum -y install tar xz && \
curl https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz -o ffmpeg.tar.xz -s && \
tar -xf ffmpeg.tar.xz && \
mv ffmpeg-*-amd64-static/ffmpeg /usr/bin && \
cd / && \
rm -rf ffmpeg
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
WORKDIR /src
COPY ["AWSServerless.csproj", "AWSServerless/"]
RUN dotnet restore "AWSServerless/AWSServerless.csproj"
WORKDIR "/src/AWSServerless"
COPY . .
RUN dotnet build "AWSServerless.csproj" --configuration Release --output /app/build
FROM build AS publish
RUN dotnet publish "AWSServerless.csproj" \
--configuration Release \
--runtime linux-x64 \
--self-contained false \
--output /app/publish \
-p:PublishReadyToRun=true
FROM base AS final
WORKDIR /var/task
CMD ["AWSServerless::AWSServerless.LambdaEntryPoint::FunctionHandlerAsync"]
COPY --from=publish /app/publish .
我正在尝试在 .net 6 dockerized 项目中使用 ffmpeg 核心包。我在 Docker 文件中安装 ffmpeg 核心,在解决方案中引用实际包 FFMpegCore 但是当我尝试应用 ffmpeg 核心库中的任何命令时,我收到错误
An error occurred trying to start process './ffmpeg' with working directory '/var/task'. No such file or directory
Docker 构建完成,没有错误。
Docker文件
FROM public.ecr.aws/lambda/dotnet:6 AS base
....
RUN apt-get install -y ffmpeg
....
FROM base AS final
WORKDIR /var/task
COPY --from=publish /app/publish .
根据 ffmpeg core 文档为了使用 ffmpeg 我需要设置它的二进制文件夹,所以我添加 ffmpeg.config.json
{
"BinaryFolder": "/var/task",
"TemporaryFilesFolder": "/tmp"
}
当我尝试执行以下命令时抛出实际错误
An error occurred trying to start process './ffmpeg' with working directory '/var/task'. No such file or directory
这是触发错误的地方
using FFMpegCore;
...
public class MyController : ControllerBase
{
public async Task<string> Get()
{
await FFMpegArguments
.FromPipeInput(new StreamPipeSource(myfile))
.OutputToPipe(new StreamPipeSink(outputStream), options => options
.WithVideoCodec("vp9")
.ForceFormat("webm"))
.ProcessAsynchronously();
...
}
}
更新:
将 BinaryFolder
位置更改为 /usr/bin
后,出现以下错误
An error occurred trying to start process '/usr/bin/ffmpeg' with working directory '/var/task'. No such file or directory
更新#2 这是我完整的Docker文件
FROM public.ecr.aws/lambda/dotnet:6 AS base
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
WORKDIR /src
COPY ["AWSServerless.csproj", "AWSServerless/"]
RUN dotnet restore "AWSServerless/AWSServerless.csproj"
WORKDIR "/src/AWSServerless"
COPY . .
RUN dotnet build "AWSServerless.csproj" --configuration Release --output /app/build
FROM build AS publish
RUN apt-get update \
&& apt-get install -y apt-utils libgdiplus libc6-dev \
&& apt-get install -y ffmpeg
RUN dotnet publish "AWSServerless.csproj" \
--configuration Release \
--runtime linux-x64 \
--self-contained false \
--output /app/publish \
-p:PublishReadyToRun=true
FROM base AS final
WORKDIR /var/task
CMD ["AWSServerless::AWSServerless.LambdaEntryPoint::FunctionHandlerAsync"]
COPY --from=publish /app/publish .
你告诉它二进制文件在 ffmpeg.config.json
中的 /var/task
中,但是 apt-get install -y ffmpeg
在 /usr/bin
中安装 ffmpeg。将 BinaryFolder
配置值更改为这样的
{
"BinaryFolder": "/usr/bin",
"TemporaryFilesFolder": "/tmp"
}
您还需要将 ffmpeg
安装在 Dockerfile 中最终映像中的某个位置。现在您将它安装在 Dockerfile 的 build/publish 部分,该部分未用于最终图像。
试试这个
FROM public.ecr.aws/lambda/dotnet:6 AS base
# Install ffmpeg
RUN mkdir /ffmpeg && \
cd /ffmpeg && \
yum -y install tar xz && \
curl https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz -o ffmpeg.tar.xz -s && \
tar -xf ffmpeg.tar.xz && \
mv ffmpeg-*-amd64-static/ffmpeg /usr/bin && \
cd / && \
rm -rf ffmpeg
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
WORKDIR /src
COPY ["AWSServerless.csproj", "AWSServerless/"]
RUN dotnet restore "AWSServerless/AWSServerless.csproj"
WORKDIR "/src/AWSServerless"
COPY . .
RUN dotnet build "AWSServerless.csproj" --configuration Release --output /app/build
FROM build AS publish
RUN dotnet publish "AWSServerless.csproj" \
--configuration Release \
--runtime linux-x64 \
--self-contained false \
--output /app/publish \
-p:PublishReadyToRun=true
FROM base AS final
WORKDIR /var/task
CMD ["AWSServerless::AWSServerless.LambdaEntryPoint::FunctionHandlerAsync"]
COPY --from=publish /app/publish .