我正在构建一个 Wasm 应用程序并编译它,我有一个 shell 脚本。
当我从终端手动运行它时,我有以下内容:
/app/Go/assets$ ./script.compile.wasm.sh
Wasm compiled
该文件的内容是:#!/bin/sh
GOOS=js GOARCH=wasm go build -o ./app.wasm ./wasm.go
echo "Wasm compiled"
wasm 文件已正确编译。但是当我从 Docker 运行它时,我得到:
Step 15/20 : RUN ./assets/compile.wasm.sh
---> Running in 38dd56259b0f
go: cannot find main module; see 'go help modules'
Wasm compiled
编译失败。Docker 行如下所示:
RUN ./assets/compile.wasm.sh
最佳答案
在您的本地情况下,您从 assets
启动脚本。目录;在 Dockerfile 案例中,您从其父目录启动它。这很重要,因为当脚本引用像 ./wasm.go
这样的文件时, 这些是相对于当前目录而不是包含脚本的目录来解析的。
您可以通过确保您在 assets
中来解决此问题。 Dockerfile 中的目录:
# Only for this command; will reset afterwards
RUN cd assets && ./compile.wasm.sh
# For this and all following commands, unless reset with another WORKDIR
WORKDIR /app/Go/assets
RUN ./compile.wasm.sh
关于docker - 找不到主模块;见 'go help modules',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62745790/