I am building a Wasm application and to compile it I have a shell script. When I run it manually from terminal I have the following:
/app/Go/assets$ ./script.compile.wasm.sh
Wasm compiled
The content of the file is:
#!/bin/sh
GOOS=js GOARCH=wasm go build -o ./app.wasm ./wasm.go
echo "Wasm compiled"
The wasm file is properly compiled.
But when I run it from Docker I get:
Step 15/20 : RUN ./assets/compile.wasm.sh
---> Running in 38dd56259b0f
go: cannot find main module; see 'go help modules'
Wasm compiled
The compilation fails.
The Docker line looks like:
RUN ./assets/compile.wasm.sh
In your local case, you're launching the script from the assets
directory; in the Dockerfile case you're launching it from its parent directory. This matters because when the script references files like ./wasm.go
, those are resolved relative to the current directory and not the directory containing the script.
You can resolve this by making sure you're in the assets
directory in the Dockerfile too:
# 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.