Home > Article > Backend Development > Why Does My Docker Image Build Fail with \'Import Path Does Not Begin with Hostname\' When Using a Local Package?
Building Docker Image with Local Package: Error "Import Path Does Not Begin with Hostname"
When attempting to build a docker image with a local package, you may encounter the error "import path does not begin with hostname." This error occurs because the Dockerfile specifies the base image golang:onbuild without including steps to obtain dependencies.
The golang:onbuild image is suitable for simple scenarios, but it does not automatically pick up application dependencies. If you need to use local code during the build process, you need to create your own Dockerfile.
You can create your own Dockerfile using the following steps:
FROM golang:1.6 ADD . /go/src/yourapplication RUN go get github.com/jadekler/git-go-websiteskeleton RUN go install yourapplication ENTRYPOINT /go/bin/yourapplication EXPOSE 8080
This Dockerfile does the following:
By using your own Dockerfile and getting the dependencies explicitly, you should be able to successfully build a Docker image containing native code.
The above is the detailed content of Why Does My Docker Image Build Fail with \'Import Path Does Not Begin with Hostname\' When Using a Local Package?. For more information, please follow other related articles on the PHP Chinese website!