我正在構(gòu)建一個(gè) Wasm 應(yīng)用程序并編譯它,我有一個(gè) shell 腳本。當(dāng)我從終端手動(dòng)運(yùn)行它時(shí),我有以下內(nèi)容:/app/Go/assets$ ./script.compile.wasm.sh Wasm compiled該文件的內(nèi)容是:#!/bin/shGOOS=js GOARCH=wasm go build -o ./app.wasm ./wasm.goecho "Wasm compiled"wasm 文件已正確編譯。但是當(dāng)我從 Docker 運(yùn)行它時(shí),我得到:Step 15/20 : RUN ./assets/compile.wasm.sh ---> Running in 38dd56259b0fgo: cannot find main module; see 'go help modules'Wasm compiled編譯失敗。Docker 行如下所示:RUN ./assets/compile.wasm.sh
1 回答

一只名叫tom的貓
TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊
在您的本地情況下,您是從assets目錄啟動(dòng)腳本;在 Dockerfile 案例中,您從其父目錄啟動(dòng)它。這很重要,因?yàn)楫?dāng)腳本引用類似的文件時(shí)./wasm.go,這些文件是相對于當(dāng)前目錄而不是包含腳本的目錄解析的。
您可以通過確保您也在assetsDockerfile 的目錄中來解決此問題:
# 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
- 1 回答
- 0 關(guān)注
- 119 瀏覽
添加回答
舉報(bào)
0/150
提交
取消