docker - 找不到主模块;见 'go help modules'

标签 docker shell go webassembly

我正在构建一个 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/

相关文章:

docker: 拉取镜像时出现 "first record does not look like a TLS handshake"错误

docker - 为什么 docker 有 docker 卷和卷容器

python - 在 alpine docker 容器中安装 psycopg2

linux - 启动使用killall杀死的服务

json - MGO 返回 bson 字段而不是 json 字段

docker - 具有相同存储库标签的图像

linux - 如何从另一个脚本中终止正在运行的脚本?

shell 脚本 : grep+while+cut+awk in a large file = very slow

go - 是否需要关闭文件?

database - 有数据库的 Authboss