Go has built-in support that makes WASM (WebAssembly) simple and possible. Let’s attempt to use WASM for the first time. A few packages are needed before running this on your system.
Begin by creating a .dockerfile and installing Docker on your host machine:
FROM golang:1.14.3-alpine
WORKDIR /app
COPY . .
RUN apk add --no-cache git
RUN go get -u github.com/shurcooL/goexec
RUN cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .
RUN GOOS=js GOARCH=wasm go build -o main.wasm
CMD ["goexec", "http.ListenAndServe(`:8080`, http.FileServer(http.Dir(`.`)))"]
Here, we have an Alpine-based Go .dockerfile
This is a minimum-sized Docker image with Go already installed.
We will create a working directory called /app
and then install git
by using the command apk add
with the argument --no-cache
.
This will prepare our Alpine instance to allow for Git modules to be pulled in later in the process.
#webassembly #wasm #docker