Docker golang + ffmpeg 执行命令失败

huangapple go评论86阅读模式
英文:

Docker golang + ffmpeg Failed to execute command

问题

你好,我正在使用以下的Docker镜像:

FROM golang:alpine3.18

同时安装了ffmpeg(可能我在这里漏掉了一些内容):

RUN apk add --no-cache ffmpeg

然而,当尝试执行以下命令时:

cmd := "ffmpeg -i Untitled.mp4 -vf \"fps=5,scale=320:-1:flags=lanczos\" -c:v pam -f image2pipe - | convert -delay 5 - -loop 0 -layers optimize test.gif"
_, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
    fmt.Println(fmt.Sprintf("Failed to execute command: %s", err))
}

我得到了这个错误:

Failed to execute command: exec: "bash": 在 $PATH 中找不到可执行文件
英文:

Hi I am using the following docker image:

FROM golang:alpine3.18

With ffmpeg: (probably here I am missing something)

RUN apk add --no-cache ffmpeg

However when trying to execute the following:

cmd := "ffmpeg -i Untitled.mp4 -vf \"fps=5,scale=320:-1:flags=lanczos\" -c:v pam -f image2pipe - | convert -delay 5 - -loop 0 -layers optimize test.gif"
_, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
	fmt.Println(fmt.Sprintf("Failed to execute command: %s", err))
}

I get this error:

 Failed to execute command: exec: "bash": executable file not found in $PATH

答案1

得分: 2

阿尔派(Alpine)的Docker镜像默认没有安装Bash,而是使用Ash shell。你可以参考这个链接Docker: How to use bash with an Alpine based docker image?中的答案。

英文:

> Alpine docker image doesn't have bash installed by default. It uses the Ash shell instead

The answer is already here Docker: How to use bash with an Alpine based docker image?

答案2

得分: 0

你尝试通过终端访问容器并执行"bash"命令了吗?
有些容器默认只支持"sh"命令。
否则,当你访问容器时,请检查你尝试用"bash"命令执行的文件是否存在于容器中,或者是否与你的机器上的卷正确链接。

英文:

Do you tried to access the container and exec "bash" by terminal?
Some containers have only "sh" command available by default.
Otherwhise when you access the container check the files that you are trying to execute with the bash command are there in the container or are well linked in your machine with volumes.

huangapple
  • 本文由 发表于 2023年5月18日 22:02:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76281583.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定