Home > Mobile >  How to access static file for webserver build via docker
How to access static file for webserver build via docker

Time:01-17

I am having an issue with accessing a static file for my local webserver when I am building it with docker. I am using the github.com/xeipuuv/gojsonschema tool kit for validating incoming json request with a local json schema file via

schemaLoader := gojsonschema.NewReferenceLoader("file://C:/Users/user/Workspace/jsonschema.json")

But when I am trying to access the file with docker it says "no such file or directory". The Dockerfile I am using is:

FROM golang:1.17-alpine
WORKDIR /app

COPY go.mod .
COPY go.sum .
COPY jsonschema.json .

RUN go mod download
COPY *.go ./
RUN go build -o /main
EXPOSE 8080
CMD ["/main"]

Thank You very much in advance. Best regards

I tried changing the directory to, i.e.

schemaLoader := gojsonschema.NewReferenceLoader("file://app/jsonschema.json")

but it didn't help.

CodePudding user response:

Your fix is nearly correct but you are missing a single / in the file:// path.

Here is an explanation of the difference between file:/, file://, and file:///.

You want this:

schemaLoader := gojsonschema.NewReferenceLoader("file:///app/jsonschema.json")

which means: use the file uri (file://) to load file with absolute path (/app/jsonschema.json).

  • Related